[SCM] NSS Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Wed Nov 4 15:36:15 UTC 2020


The branch, master has been updated
       via  7bdf2f8 nwrap_files_cache_reload: add close for ebadf fd just incase
       via  5d2b47f nwrap_files_cache_reload: add test for closed handles error
       via  95b1e79 nwrap_files_cache_reload: avoid error on EBADF during stat
      from  86420d9 nwrap_files_getaddrinfo: avoid crash on empty name

https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7bdf2f87f4e63d57f0d9a939e0e78349d1b71342
Author: TJ Miller <millert at us.ibm.com>
Date:   Wed Oct 28 13:55:59 2020 -0700

    nwrap_files_cache_reload: add close for ebadf fd just incase
    
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 5d2b47fdd89c3834b226a56703cb51be8b937d21
Author: TJ Miller <millert at us.ibm.com>
Date:   Wed Oct 28 13:54:48 2020 -0700

    nwrap_files_cache_reload: add test for closed handles error
    
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 95b1e79a1f6ee0f1248723a3466fcce125db650f
Author: TJ Miller <millert at us.ibm.com>
Date:   Thu Oct 15 12:07:17 2020 -0700

    nwrap_files_cache_reload: avoid error on EBADF during stat
    
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/nss_wrapper.c            | 16 +++++++++++++++-
 tests/test_getpwuid_module.c | 25 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 4f4dc93..877f6d1 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -2129,7 +2129,21 @@ reopen:
 	}
 
 	ret = fstat(nwrap->fd, &st);
-	if (ret != 0) {
+	if (ret != 0 && errno == EBADF && retried == false) {
+		/* maybe something closed the fd on our behalf */
+		NWRAP_LOG(NWRAP_LOG_TRACE,
+			  "fstat(%s) - %d:%s - reopen",
+			  nwrap->path,
+			  ret,
+			  strerror(errno));
+		retried = true;
+		memset(&nwrap->st, 0, sizeof(nwrap->st));
+		fclose(nwrap->fp);
+		nwrap->fp = NULL;
+		nwrap->fd = -1;
+		goto reopen;
+	}
+	else if (ret != 0) {
 		NWRAP_LOG(NWRAP_LOG_ERROR,
 			  "fstat(%s) - %d:%s",
 			  nwrap->path,
diff --git a/tests/test_getpwuid_module.c b/tests/test_getpwuid_module.c
index 2dbecb1..a06a49d 100644
--- a/tests/test_getpwuid_module.c
+++ b/tests/test_getpwuid_module.c
@@ -4,6 +4,7 @@
 #include <stddef.h>
 #include <setjmp.h>
 #include <cmocka.h>
+#include <unistd.h>
 
 #include <pwd.h>
 
@@ -22,12 +23,36 @@ static void test_nwrap_passwd(void **state)
 	assert_int_equal(pwd->pw_gid, id);
 }
 
+static void test_nwrap_passwd_closed_handles(void **state)
+{
+	struct passwd *pwd;
+	uid_t id = 424242;
+	long maxfd;
+
+	(void) state; /* unused */
+
+	pwd = getpwuid(id);
+	assert_non_null(pwd);
+
+	maxfd = sysconf(_SC_OPEN_MAX);
+	if (maxfd < 0) {
+		maxfd = 1024;
+	}
+	for (long fd = 3; fd < maxfd; fd++) {
+		close(fd);
+	}
+
+	pwd = getpwuid(id);
+	assert_non_null(pwd);
+}
+
 int main(void)
 {
 	int rc;
 
 	const struct CMUnitTest tests[] = {
 		cmocka_unit_test(test_nwrap_passwd),
+		cmocka_unit_test(test_nwrap_passwd_closed_handles),
 	};
 
 	rc = cmocka_run_group_tests(tests, NULL, NULL);


-- 
NSS Wrapper Repository



More information about the samba-cvs mailing list