From 08d1666b99533f8a72a4ef2c8abe77be8058d0e0 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 29 May 2022 21:46:16 -0400 Subject: [PATCH 7/7] bindat (strz): Fix packing of long strings with legacy-style spec * lisp/emacs-lisp/bindat.el (strz): Call the proper handler when packing to fix lack of null terminator when packing strings with length greater than or equal to the declared length. * test/lisp/emacs-lisp/bindat-tests.el (strz): Mark test as passing. --- lisp/emacs-lisp/bindat.el | 3 ++- test/lisp/emacs-lisp/bindat-tests.el | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index cf17e5764d..e8eb59e24d 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -480,7 +480,8 @@ bindat--pack-item ('u24r (bindat--pack-u24r v)) ('u32r (bindat--pack-u32r v)) ('bits (bindat--pack-bits len v)) - ((or 'str 'strz) (bindat--pack-str len v)) + ('str (bindat--pack-str len v)) + ('strz (bindat--pack-strz len v)) ('vec (let ((l (length v)) (vlen 1)) (if (consp vectype) diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index 01f9d51ad0..ca93a2468b 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -211,7 +211,6 @@ bindat-test--recursive (should (equal (bindat-pack spec '((x . "a"))) "\141\0"))) (ert-deftest bindat-test--strz-legacy-fixedlen-pack-overflow () - :expected-result :failed (should (equal (bindat-pack spec '((x . "abc"))) "\141\0"))) (ert-deftest bindat-test--strz-legacy-fixedlen-unpack () -- 2.36.1