mkdir: make safe for libraries
authorEric Blake <ebb9@byu.net>
Thu, 29 Oct 2009 15:37:42 +0000 (09:37 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 30 Oct 2009 00:39:31 +0000 (18:39 -0600)
xstrdup is too dangerous to use in a syscall replacement.

* modules/mkdir (Depends-on): Drop xalloc.
* lib/mkdir.c (rpl_mkdir): Fail with ENOMEM rather than calling
exit.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/mkdir.c
modules/mkdir

index bda6fbb..27528cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-29  Eric Blake  <ebb9@byu.net>
 
+       mkdir: make safe for libraries
+       * modules/mkdir (Depends-on): Drop xalloc.
+       * lib/mkdir.c (rpl_mkdir): Fail with ENOMEM rather than calling
+       exit.
+
        tests: avoid some compiler warnings
        * tests/test-getaddrinfo.c (simple): Mark static, and allow string
        literals.
index 3d9f043..e6dbc78 100644 (file)
@@ -56,7 +56,13 @@ rpl_mkdir (char const *dir, mode_t mode maybe_unused)
 
   if (len && dir[len - 1] == '/')
     {
-      tmp_dir = xstrdup (dir);
+      tmp_dir = strdup (dir);
+      if (!tmp_dir)
+        {
+          /* Rather than rely on strdup-posix, we set errno ourselves.  */
+          errno = ENOMEM;
+          return -1;
+        }
       strip_trailing_slashes (tmp_dir);
     }
   else
index 59d60fb..fa0931d 100644 (file)
@@ -7,7 +7,6 @@ m4/mkdir.m4
 
 Depends-on:
 sys_stat
-xalloc
 dirname
 
 configure.ac: