public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/google/grte/v5-2.27/master] Handle a not-found case in borg passwd lookup
@ 2021-08-28  0:40 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-28  0:40 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=21c2ca10b15f8af6265e8d018ede671e9159cd72

commit 21c2ca10b15f8af6265e8d018ede671e9159cd72
Author: Stan Shebs <stanshebs@google.com>
Date:   Thu Nov 3 16:31:52 2016 -0700

    Handle a not-found case in borg passwd lookup

Diff:
---
 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 9b68b9bec7..3bbe6efcba 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 {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-28  0:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28  0:40 [glibc/google/grte/v5-2.27/master] Handle a not-found case in borg passwd lookup Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).