]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Handle a not-found case in borg passwd lookup
authorStan Shebs <stanshebs@google.com>
Thu, 3 Nov 2016 23:31:52 +0000 (16:31 -0700)
committerStan Shebs <stanshebs@google.com>
Thu, 3 Nov 2016 23:31:52 +0000 (16:31 -0700)
nss/nss_borg/borg-pwd.c

index 9b68b9bec72774e92dbea327fbc0833af710e6d7..3bbe6efcbac267144889c2e797b96b89d2bd2251 100644 (file)
@@ -86,13 +86,16 @@ static enum nss_status _nss_borg_getpwent_r_locked(struct passwd *result,
                                                    int *errnop) {
 
   enum nss_status ret;
-
+  // Save a copy of the buffer address, in case first call errors
+  // and sets it to 0.
+  struct passwd *sparecopy = result;
   if (
       f != NULL && (fgetpwent_r(f, result, buffer, buflen, &result) == 0)) {
     DEBUG("Returning borg user %d:%s\n", result->pw_uid, result->pw_name);
     ret = NSS_STATUS_SUCCESS;
   } else if (
-      fb != NULL && (fgetpwent_r(fb, result, buffer, buflen, &result) == 0)) {
+            // Yes, this is one of those cases where an assign makes sense.
+            fb != NULL && (result = sparecopy) && (fgetpwent_r(fb, result, buffer, buflen, &result) == 0)) {
     DEBUG("Returning base user %d:%s\n", result->pw_uid, result->pw_name);
     ret = NSS_STATUS_SUCCESS;
   } else {