aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2025-01-31 10:41:28 +0200
committerEli Zaretskii2025-01-31 10:41:28 +0200
commitf54f798588ee5f0b6ba4ebbc1c1b395c19845a2f (patch)
tree572fcfe4ee312edfcf2f3ec156fbf7e13d2e1d93
parentf45a776fe3c9160c49fdf21a96d37d2ed780836c (diff)
downloademacs-f54f798588ee5f0b6ba4ebbc1c1b395c19845a2f.tar.gz
emacs-f54f798588ee5f0b6ba4ebbc1c1b395c19845a2f.zip
Avoid stack overflow on MS-Windows due to 'make-temp-name'
* src/fileio.c (Fexpand_file_name) [DOS_NT]: Use 'SAFE_ALLOCA' instead of 'alloca'. (Bug#75938)
-rw-r--r--src/fileio.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/fileio.c b/src/fileio.c
index d832967bb6b..cb131264492 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1450,7 +1450,7 @@ the root directory. */)
1450 char *adir = NULL; 1450 char *adir = NULL;
1451 if (!IS_DIRECTORY_SEP (nm[0])) 1451 if (!IS_DIRECTORY_SEP (nm[0]))
1452 { 1452 {
1453 adir = alloca (MAXPATHLEN + 1); 1453 adir = SAFE_ALLOCA (MAXPATHLEN + 1);
1454 if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) 1454 if (!getdefdir (c_toupper (drive) - 'A' + 1, adir))
1455 adir = NULL; 1455 adir = NULL;
1456 else if (multibyte) 1456 else if (multibyte)
@@ -1467,7 +1467,7 @@ the root directory. */)
1467 if (!adir) 1467 if (!adir)
1468 { 1468 {
1469 /* Either nm starts with /, or drive isn't mounted. */ 1469 /* Either nm starts with /, or drive isn't mounted. */
1470 adir = alloca (4); 1470 adir = SAFE_ALLOCA (4);
1471 adir[0] = DRIVE_LETTER (drive); 1471 adir[0] = DRIVE_LETTER (drive);
1472 adir[1] = ':'; 1472 adir[1] = ':';
1473 adir[2] = '/'; 1473 adir[2] = '/';
@@ -1540,7 +1540,7 @@ the root directory. */)
1540 { 1540 {
1541 ptrdiff_t nmlen = nmlim - nm; 1541 ptrdiff_t nmlen = nmlim - nm;
1542 ptrdiff_t newdirlen = newdirlim - newdir; 1542 ptrdiff_t newdirlen = newdirlim - newdir;
1543 char *tmp = alloca (newdirlen + file_name_as_directory_slop 1543 char *tmp = SAFE_ALLOCA (newdirlen + file_name_as_directory_slop
1544 + nmlen + 1); 1544 + nmlen + 1);
1545 ptrdiff_t dlen = file_name_as_directory (tmp, newdir, newdirlen, 1545 ptrdiff_t dlen = file_name_as_directory (tmp, newdir, newdirlen,
1546 multibyte); 1546 multibyte);
@@ -1548,7 +1548,7 @@ the root directory. */)
1548 nm = tmp; 1548 nm = tmp;
1549 nmlim = nm + dlen + nmlen; 1549 nmlim = nm + dlen + nmlen;
1550 } 1550 }
1551 adir = alloca (adir_size); 1551 adir = SAFE_ALLOCA (adir_size);
1552 if (drive) 1552 if (drive)
1553 { 1553 {
1554 if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) 1554 if (!getdefdir (c_toupper (drive) - 'A' + 1, adir))
@@ -1584,7 +1584,7 @@ the root directory. */)
1584 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]) 1584 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])
1585 && !IS_DIRECTORY_SEP (newdir[2])) 1585 && !IS_DIRECTORY_SEP (newdir[2]))
1586 { 1586 {
1587 char *adir = strcpy (alloca (newdirlim - newdir + 1), newdir); 1587 char *adir = strcpy (SAFE_ALLOCA (newdirlim - newdir + 1), newdir);
1588 char *p = adir + 2; 1588 char *p = adir + 2;
1589 while (*p && !IS_DIRECTORY_SEP (*p)) p++; 1589 while (*p && !IS_DIRECTORY_SEP (*p)) p++;
1590 p++; 1590 p++;
@@ -1614,7 +1614,7 @@ the root directory. */)
1614 /* Reserve space for drive specifier and escape prefix, since either 1614 /* Reserve space for drive specifier and escape prefix, since either
1615 or both may need to be inserted. (The Microsoft x86 compiler 1615 or both may need to be inserted. (The Microsoft x86 compiler
1616 produces incorrect code if the following two lines are combined.) */ 1616 produces incorrect code if the following two lines are combined.) */
1617 target = alloca (tlen + 4); 1617 target = SAFE_ALLOCA (tlen + 4);
1618 target += 4; 1618 target += 4;
1619#else /* not DOS_NT */ 1619#else /* not DOS_NT */
1620 target = SAFE_ALLOCA (tlen); 1620 target = SAFE_ALLOCA (tlen);