---
** 'remove-hook' is now an interactive command.
+** 'expand-file-name' now checks for null bytes in filenames.
+The function will now check for null bytes in both NAME and
+DEFAULT-DIRECTORY arguments, as well as in the 'default-directory'
+buffer-local variable, assuming its value is used. If null bytes are
+found, 'expand-file-name' will signal an error.
+
+---
** Frames
+++
cause subtle bugs because the system would silently use a
different filename than expected. Perform this check after
encoding to not miss NUL bytes introduced through encoding. */
- CHECK_TYPE (memchr (SSDATA (encoded), '\0', SBYTES (encoded)) == NULL,
- Qfilenamep, fname);
+ CHECK_STRING_NULL_BYTES (encoded);
return encoded;
}
USE_SAFE_ALLOCA;
CHECK_STRING (name);
+ CHECK_STRING_NULL_BYTES (name);
/* If the file name has special constructs in it,
call the corresponding file name handler. */
if (STRINGP (dir))
{
if (file_name_absolute_no_tilde_p (dir))
- default_directory = dir;
+ {
+ CHECK_STRING_NULL_BYTES (dir);
+ default_directory = dir;
+ }
else
{
Lisp_Object absdir
XSTRING (string)->u.s.size = newsize;
}
+INLINE void
+CHECK_STRING_NULL_BYTES (Lisp_Object string)
+{
+ CHECK_TYPE (memchr (SSDATA (string), '\0', SBYTES (string)) == NULL,
+ Qfilenamep, string);
+}
+
/* A regular vector is just a header plus an array of Lisp_Objects. */
struct Lisp_Vector
(should (and (file-name-absolute-p name)
(not (eq (aref name 0) ?~))))))
+(ert-deftest fileio-test--expand-file-name-null-bytes ()
+ "Test that expand-file-name checks for null bytes in filenames."
+ (should-error (expand-file-name (concat "file" (char-to-string ?\0) ".txt"))
+ :type 'wrong-type-argument)
+ (should-error (expand-file-name "file.txt" (concat "dir" (char-to-string ?\0)))
+ :type 'wrong-type-argument)
+ (let ((default-directory (concat "dir" (char-to-string ?\0))))
+ (should-error (expand-file-name "file.txt") :type 'wrong-type-argument)))
+
(ert-deftest fileio-tests--file-name-absolute-p ()
"Test file-name-absolute-p."
(dolist (suffix '("" "/" "//" "/foo" "/foo/" "/foo//" "/foo/bar"))