diff options
| author | Eli Zaretskii | 2012-11-18 18:43:36 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-11-18 18:43:36 +0200 |
| commit | 273ac8d1ef96529d010975b59caa99489cbc51b4 (patch) | |
| tree | 912938697aac6cc0eb5ab3234c6ebe4f6b2008a9 /src | |
| parent | 66c466d4fdb7f874f19191ca06fad92f9c2393cd (diff) | |
| download | emacs-273ac8d1ef96529d010975b59caa99489cbc51b4.tar.gz emacs-273ac8d1ef96529d010975b59caa99489cbc51b4.zip | |
Prevent crashes on MS-Windows when w32-downcase-file-names is non-nil.
src/fileio.c (Fsubstitute_in_file_name, Ffile_name_directory)
(Fexpand_file_name) [DOS_NT]: Pass encoded file name to
dostounix_filename. Prevents crashes down the road, because
dostounix_filename assumes it gets a unibyte string. Reported by
Michel de Ruiter <michel@sentient.nl>, see
http://lists.gnu.org/archive/html/help-emacs-windows/2012-11/msg00017.html
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/fileio.c | 46 |
2 files changed, 46 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c12eff19ddd..c4f1ee60d84 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-11-18 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * fileio.c (Fsubstitute_in_file_name, Ffile_name_directory) | ||
| 4 | (Fexpand_file_name) [DOS_NT]: Pass encoded file name to | ||
| 5 | dostounix_filename. Prevents crashes down the road, because | ||
| 6 | dostounix_filename assumes it gets a unibyte string. Reported by | ||
| 7 | Michel de Ruiter <michel@sentient.nl>, see | ||
| 8 | http://lists.gnu.org/archive/html/help-emacs-windows/2012-11/msg00017.html | ||
| 9 | |||
| 1 | 2012-11-17 Eli Zaretskii <eliz@gnu.org> | 10 | 2012-11-17 Eli Zaretskii <eliz@gnu.org> |
| 2 | 11 | ||
| 3 | * w32select.c: Include w32common.h before w32term.h, so that | 12 | * w32select.c: Include w32common.h before w32term.h, so that |
diff --git a/src/fileio.c b/src/fileio.c index d47d7dd9e0b..a04eb8ecea1 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -315,6 +315,7 @@ Given a Unix syntax file name, returns a string ending in slash. */) | |||
| 315 | register const char *beg; | 315 | register const char *beg; |
| 316 | #else | 316 | #else |
| 317 | register char *beg; | 317 | register char *beg; |
| 318 | Lisp_Object tem_fn; | ||
| 318 | #endif | 319 | #endif |
| 319 | register const char *p; | 320 | register const char *p; |
| 320 | Lisp_Object handler; | 321 | Lisp_Object handler; |
| @@ -374,10 +375,13 @@ Given a Unix syntax file name, returns a string ending in slash. */) | |||
| 374 | p = beg + strlen (beg); | 375 | p = beg + strlen (beg); |
| 375 | } | 376 | } |
| 376 | } | 377 | } |
| 377 | dostounix_filename (beg); | 378 | tem_fn = ENCODE_FILE (make_specified_string (beg, -1, p - beg, |
| 378 | #endif /* DOS_NT */ | 379 | STRING_MULTIBYTE (filename))); |
| 379 | 380 | dostounix_filename (SSDATA (tem_fn)); | |
| 381 | return DECODE_FILE (tem_fn); | ||
| 382 | #else /* DOS_NT */ | ||
| 380 | return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename)); | 383 | return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename)); |
| 384 | #endif /* DOS_NT */ | ||
| 381 | } | 385 | } |
| 382 | 386 | ||
| 383 | DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, | 387 | DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, |
| @@ -951,7 +955,18 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 951 | #ifdef DOS_NT | 955 | #ifdef DOS_NT |
| 952 | /* Make sure directories are all separated with /, but | 956 | /* Make sure directories are all separated with /, but |
| 953 | avoid allocation of a new string when not required. */ | 957 | avoid allocation of a new string when not required. */ |
| 954 | dostounix_filename (nm); | 958 | if (multibyte) |
| 959 | { | ||
| 960 | Lisp_Object tem_name = make_specified_string (nm, -1, strlen (nm), | ||
| 961 | multibyte); | ||
| 962 | |||
| 963 | tem_name = ENCODE_FILE (tem_name); | ||
| 964 | dostounix_filename (SSDATA (tem_name)); | ||
| 965 | tem_name = DECODE_FILE (tem_name); | ||
| 966 | memcpy (nm, SSDATA (tem_name), SBYTES (tem_name) + 1); | ||
| 967 | } | ||
| 968 | else | ||
| 969 | dostounix_filename (nm); | ||
| 955 | #ifdef WINDOWSNT | 970 | #ifdef WINDOWSNT |
| 956 | if (IS_DIRECTORY_SEP (nm[1])) | 971 | if (IS_DIRECTORY_SEP (nm[1])) |
| 957 | { | 972 | { |
| @@ -1305,10 +1320,13 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1305 | target[0] = '/'; | 1320 | target[0] = '/'; |
| 1306 | target[1] = ':'; | 1321 | target[1] = ':'; |
| 1307 | } | 1322 | } |
| 1308 | dostounix_filename (target); | ||
| 1309 | #endif /* DOS_NT */ | ||
| 1310 | |||
| 1311 | result = make_specified_string (target, -1, o - target, multibyte); | 1323 | result = make_specified_string (target, -1, o - target, multibyte); |
| 1324 | result = ENCODE_FILE (result); | ||
| 1325 | dostounix_filename (SSDATA (result)); | ||
| 1326 | result = DECODE_FILE (result); | ||
| 1327 | #else /* !DOS_NT */ | ||
| 1328 | result = make_specified_string (target, -1, o - target, multibyte); | ||
| 1329 | #endif /* !DOS_NT */ | ||
| 1312 | } | 1330 | } |
| 1313 | 1331 | ||
| 1314 | /* Again look to see if the file name has special constructs in it | 1332 | /* Again look to see if the file name has special constructs in it |
| @@ -1587,8 +1605,18 @@ those `/' is discarded. */) | |||
| 1587 | memcpy (nm, SDATA (filename), SBYTES (filename) + 1); | 1605 | memcpy (nm, SDATA (filename), SBYTES (filename) + 1); |
| 1588 | 1606 | ||
| 1589 | #ifdef DOS_NT | 1607 | #ifdef DOS_NT |
| 1590 | dostounix_filename (nm); | 1608 | { |
| 1591 | substituted = (strcmp (nm, SDATA (filename)) != 0); | 1609 | Lisp_Object encoded_filename = ENCODE_FILE (filename); |
| 1610 | Lisp_Object tem_fn; | ||
| 1611 | |||
| 1612 | dostounix_filename (SDATA (encoded_filename)); | ||
| 1613 | tem_fn = DECODE_FILE (encoded_filename); | ||
| 1614 | nm = alloca (SBYTES (tem_fn) + 1); | ||
| 1615 | memcpy (nm, SDATA (tem_fn), SBYTES (tem_fn) + 1); | ||
| 1616 | substituted = (memcmp (nm, SDATA (filename), SBYTES (filename)) != 0); | ||
| 1617 | if (substituted) | ||
| 1618 | filename = tem_fn; | ||
| 1619 | } | ||
| 1592 | #endif | 1620 | #endif |
| 1593 | endp = nm + SBYTES (filename); | 1621 | endp = nm + SBYTES (filename); |
| 1594 | 1622 | ||