summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Tedin <federicotedin@gmail.com>2021-09-15 00:15:16 +0200
committerEli Zaretskii <eliz@gnu.org>2021-09-18 09:36:26 +0300
commit4e21c5f451a18f96172e63dbe8a3ceef780758bb (patch)
treeeb8e8408ac1db13a0892eb20818189e3f3f086fd /src
parent62e870691d2192e7848e047734556dec21797a7b (diff)
Check for null bytes in filenames in 'expand-file-name' (bug#49723)
* src/fileio.c (expand-file-name): Check for null bytes for both NAME and DEFAULT-DIRECTORY arguments. Also check for null bytes in buffer-local default-directory, assuming it is used. * src/coding.c (encode_file_name): Use CHECK_STRING_NULL_BYTES. * src/lisp.h (CHECK_STRING_NULL_BYTES): Add function for checking for null bytes in Lisp strings. * test/src/fileio-tests.el (fileio-test--expand-file-name-null-bytes): Add test for new changes to expand-file-name. * etc/NEWS: Announce changes.
Diffstat (limited to 'src')
-rw-r--r--src/coding.c3
-rw-r--r--src/fileio.c6
-rw-r--r--src/lisp.h7
3 files changed, 13 insertions, 3 deletions
diff --git a/src/coding.c b/src/coding.c
index d027c7d5399..7030a53869a 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -10430,8 +10430,7 @@ encode_file_name (Lisp_Object fname)
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;
}
diff --git a/src/fileio.c b/src/fileio.c
index 0db8ed793b3..3c13d3fe416 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -945,6 +945,7 @@ the root directory. */)
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. */
@@ -993,7 +994,10 @@ the root directory. */)
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
diff --git a/src/lisp.h b/src/lisp.h
index 7bfc69b647b..9716b34baee 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1615,6 +1615,13 @@ STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
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