- 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);
+