From: ticktock35 Date: Mon, 15 Dec 2008 04:53:20 +0000 (+0000) Subject: opkg/libbb: Patch from Esben Haabendal X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=77bfb4c70257f7c85ace0e5ee975e4321fdd667a;p=oweals%2Fopkg-lede.git opkg/libbb: Patch from Esben Haabendal Fix the usage of dirname() in libbb/make_directory.c, as it is not correct according to the standard specification for dirname. git-svn-id: http://opkg.googlecode.com/svn/trunk@48 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 797ce27..5fa2a7e 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -50,17 +50,25 @@ int make_directory (const char *path, long mode, int flags) 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;