The uage of dirname() in libbb/make_directory.c is not correct according to the standard specification for dirname. It just happens to work with glibc on Linux, but it is probably best to fix it.<br><br>From dirname(3):<br>
<br>These functions may return pointers to statically allocated memory which may be overwritten by subsequent calls. Alternatively, they may return a pointer to some part of path, so that the string referred to by path should not be modified or freed until the pointer returned by the function is no longer required.<br>
<br>On cygwin, ipkg (and thus opkg) make_directory() actually crashes.<br><br>/Esben<br><br><br><br>diff -urN ipkg-0.99.163-orig/libbb/make_directory.c ipkg-0.99.163/libbb/make_directory.c<br>--- ipkg-0.99.163-orig/libbb/make_directory.c 2006-02-06 09:13:02.000000000 +0100<br>
+++ ipkg-0.99.163/libbb/make_directory.c 2007-11-22 11:32:49.000000000 +0100<br>@@ -50,17 +50,23 @@<br> <br> if (stat (path, &st) < 0 && errno == ENOENT) {<br> int status;<br>
- char *buf, *parent;<br>+ char *pathcopy, *parent, *parentcopy;<br> mode_t mask;<br> <br> mask = umask (0);<br> umask (mask);<br>
<br>- buf = xstrdup (path);<br>- parent = dirname (buf);<br>- status = make_directory (parent, (0777 & ~mask) | 0300,<br>- FILEUTILS_RECUR);<br>
- free (buf);<br>+ /* dirname is unsafe, it may both modify the<br>+ memory of the path argument and may return<br>+ a pointer to static memory, which can then<br>
+ be modified by consequtive calls to dirname */<br>+ pathcopy = xstrdup (path);<br>+ parent = dirname (pathcopy);<br>+ parentcopy = xstrdup (parent);<br>
+ status = make_directory (parentcopy, (0777 & ~mask)<br>+ | 0300, FILEUTILS_RECUR);<br>+ free (pathcopy);<br>+ free (parentcopy);<br>
<br> if (status < 0 || make_directory (path, mode, 0) < 0)<br> return -1;<br>