From 21c2ca10b15f8af6265e8d018ede671e9159cd72 Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Thu, 3 Nov 2016 16:31:52 -0700 Subject: [PATCH] Handle a not-found case in borg passwd lookup --- nss/nss_borg/borg-pwd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nss/nss_borg/borg-pwd.c b/nss/nss_borg/borg-pwd.c index 9b68b9bec72..3bbe6efcbac 100644 --- a/nss/nss_borg/borg-pwd.c +++ b/nss/nss_borg/borg-pwd.c @@ -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 { -- 2.47.2