From: Eric Blake Date: Wed, 16 Sep 2009 19:51:50 +0000 (-0600) Subject: canonicalize: don't lose errno X-Git-Tag: v0.1~5476 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=34e0afdb6e79191a794f1a68280dff7a65721031;p=gnulib.git canonicalize: don't lose errno canonicalize-lgpl was already immune; glibc has the same bug: http://sources.redhat.com/bugzilla/show_bug.cgi?id=10635 * lib/canonicalize.c (canonicalize_filename_mode): Protect errno over calls to free. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 33507bb9e..b078c1ba2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-17 Eric Blake + canonicalize: don't lose errno + * lib/canonicalize.c (canonicalize_filename_mode): Protect errno + over calls to free. + canonicalize: simplify errno handling * lib/canonicalize.c (__set_errno): Delete macro, and use direct assignment. diff --git a/lib/canonicalize.c b/lib/canonicalize.c index c0a814d4c..402a8ff17 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -152,6 +152,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) char const *rname_limit; size_t extra_len = 0; Hash_table *ht = NULL; + int saved_errno; if (name == NULL) { @@ -239,6 +240,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) if (lstat (rname, &st) != 0) { + saved_errno = errno; if (can_mode == CAN_EXISTING) goto error; if (can_mode == CAN_ALL_BUT_LAST && *end) @@ -259,7 +261,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { if (can_mode == CAN_MISSING) continue; - errno = ELOOP; + saved_errno = ELOOP; goto error; } @@ -268,6 +270,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { if (can_mode == CAN_MISSING && errno != ENOMEM) continue; + saved_errno = errno; goto error; } @@ -303,7 +306,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING)) { - errno = ENOTDIR; + saved_errno = ENOTDIR; goto error; } } @@ -323,5 +326,6 @@ error: free (rname); if (ht) hash_free (ht); + errno = saved_errno; return NULL; }