r4195 - trunk/src/target/opkg/libbb
thomas at sita.openmoko.org
thomas at sita.openmoko.org
Wed Mar 12 18:09:36 CET 2008
Author: thomas
Date: 2008-03-12 18:09:35 +0100 (Wed, 12 Mar 2008)
New Revision: 4195
Modified:
trunk/src/target/opkg/libbb/make_directory.c
Log:
opkg/libbb: Patch from Esben Haabendal <esbenhaabendal gmail com>
Fix the usage of dirname() in libbb/make_directory.c, as it is not correct according to the standard specification for dirname.
Modified: trunk/src/target/opkg/libbb/make_directory.c
===================================================================
--- trunk/src/target/opkg/libbb/make_directory.c 2008-03-12 11:35:24 UTC (rev 4194)
+++ trunk/src/target/opkg/libbb/make_directory.c 2008-03-12 17:09:35 UTC (rev 4195)
@@ -50,18 +50,26 @@
if (stat (path, &st) < 0 && errno == ENOENT) {
int status;
- char *buf, *parent;
+ char *pathcopy, *parent, *parentcopy;
mode_t mask;
mask = umask (0);
umask (mask);
- buf = xstrdup (path);
- parent = dirname (buf);
- status = make_directory (parent, (0777 & ~mask) | 0300,
- FILEUTILS_RECUR);
- free (buf);
+ /* dirname is unsafe, it may both modify the
+ memory of the path argument and may return
+ a pointer to static memory, which can then
+ be modified by consequtive calls to dirname */
+
+ pathcopy = xstrdup (path);
+ parent = dirname (pathcopy);
+ parentcopy = xstrdup (parent);
+ status = make_directory (parentcopy, (0777 & ~mask)
+ | 0300, FILEUTILS_RECUR);
+ free (pathcopy);
+ free (parentcopy);
+
if (status < 0 || make_directory (path, mode, 0) < 0)
return -1;
}
More information about the commitlog
mailing list