diff options
author | Richard Hansen <rhansen@rhansen.org> | 2022-06-13 14:32:01 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-06-13 15:33:12 +0200 |
commit | 86325f960af8eb1df712e2f26e2b708f80c14ac6 (patch) | |
tree | 8e13db67d9fa1bfe48e398791f752f5ddfc1a999 /test/lisp/emacs-lisp/bindat-tests.el | |
parent | 86f30c972bb421db1b8f83951ecfc15ad607fb03 (diff) | |
download | emacs-86325f960af8eb1df712e2f26e2b708f80c14ac6.tar.gz emacs-86325f960af8eb1df712e2f26e2b708f80c14ac6.tar.bz2 emacs-86325f960af8eb1df712e2f26e2b708f80c14ac6.zip |
bindat (strz): Error on null byte if packing variable-length string
* lisp/emacs-lisp/bindat.el (strz): Signal an error if a null byte is
encountered while packing a string to a variable-length strz field.
* test/lisp/emacs-lisp/bindat-tests.el (strz): Add tests (bug#55938).
Diffstat (limited to 'test/lisp/emacs-lisp/bindat-tests.el')
-rw-r--r-- | test/lisp/emacs-lisp/bindat-tests.el | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index 8bb3baa485e..7d1233ded7c 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -240,7 +240,12 @@ (ert-deftest bindat-test--strz-varlen-pack () (should (equal (bindat-pack spec "") "\0")) - (should (equal (bindat-pack spec "abc") "abc\0"))) + (should (equal (bindat-pack spec "abc") "abc\0")) + ;; Null bytes in the input string break unpacking. + (should-error (bindat-pack spec "\0")) + (should-error (bindat-pack spec "\0x")) + (should-error (bindat-pack spec "x\0")) + (should-error (bindat-pack spec "x\0y"))) (ert-deftest bindat-test--strz-varlen-unpack () (should (equal (bindat-unpack spec "\0") "")) |