summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2020-06-29 12:32:56 +0200
committerPhilipp Stephani <phst@google.com>2020-06-29 12:32:56 +0200
commit59e768d64ad97782249fda9e53b6adc94c6d0130 (patch)
tree3221ba10b639751b10a067c1fab8017830ab46f2 /test
parentcce00bef0313bc42beee8096d9312313889dc92d (diff)
downloademacs-59e768d64ad97782249fda9e53b6adc94c6d0130.tar.gz
Fix undefined behavior in json.c (Bug#42113)
* src/json.c (lisp_to_json_toplevel_1, Fjson_parse_string): Check whether input strings are actually strings. * test/src/json-tests.el (json-parse-string/wrong-type) (json-serialize/wrong-hash-key-type): New regression tests.
Diffstat (limited to 'test')
-rw-r--r--test/src/json-tests.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 7eeef885198..028f92f29d3 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -296,5 +296,17 @@ Test with both unibyte and multibyte strings."
(1+ most-positive-fixnum)
(1- most-negative-fixnum)))))
+(ert-deftest json-parse-string/wrong-type ()
+ "Check that Bug#42113 is fixed."
+ (skip-unless (fboundp 'json-parse-string))
+ (should-error (json-parse-string 1) :type 'wrong-type-argument))
+
+(ert-deftest json-serialize/wrong-hash-key-type ()
+ "Check that Bug#42113 is fixed."
+ (skip-unless (fboundp 'json-serialize))
+ (let ((table (make-hash-table :test #'eq)))
+ (puthash 1 2 table)
+ (should-error (json-serialize table) :type 'wrong-type-argument)))
+
(provide 'json-tests)
;;; json-tests.el ends here