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 /lisp/emacs-lisp | |
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 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/bindat.el | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index 2d6589b52de..9ba89a5e3fe 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -444,6 +444,11 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (let* ((v (string-to-unibyte v)) (len (length v))) (dotimes (i len) + (when (= (aref v i) 0) + ;; Alternatively we could pretend that this was the end of + ;; the string and stop packing, but then bindat-length would + ;; need to scan the input string looking for a null byte. + (error "Null byte encountered in input strz string")) (aset bindat-raw (+ bindat-idx i) (aref v i))) (setq bindat-idx (+ bindat-idx len 1)))) |