Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12211:76cbe8b29dce
mkdir: make safe for libraries
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>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 29 Oct 2009 09:37:42 -0600 |
parents | 441d8820b5a5 |
children | 8bf6ff9a34bd |
files | ChangeLog lib/mkdir.c modules/mkdir |
diffstat | 3 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/lib/mkdir.c +++ b/lib/mkdir.c @@ -56,7 +56,13 @@ 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