[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Nov 13 10:12:02 UTC 2018


The branch, master has been updated
       via  9f5768106fd replace: Add check for variable program_invocation_short_name
       via  63a9fe1d445 nsswitch: Handle possible NULL return value of getprogname()
       via  7a9d003d01a lib:replace: Do not leak the file pointer in rep_getprogname()
      from  716715496c4 smbd: Use wire_perms_to_unix in unix_perms_from_wire

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


- Log -----------------------------------------------------------------
commit 9f5768106fd43935bc2725ec1b2ecce5c69f1a34
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 13 10:05:21 2018 +1100

    replace: Add check for variable program_invocation_short_name
    
    It appears that wafsamba's configure() defines _GNU_SOURCE
    unconditionally, so checking _GNU_SOURCE isn't enough to know if this
    variable is available.
    
    For example, it isn't available on AIX with the xlc compiler:
    
      [ 6/10] Compiling lib/replace/replace.c
      ...
      "../../lib/replace/replace.c", line 991.16: 1506-045 (S) Undeclared identifier program_invocation_short_name.
    
    Instead, add a configure check for program_invocation_short_name and
    use it.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Tue Nov 13 11:11:11 CET 2018 on sn-devel-144

commit 63a9fe1d445f04eb83a7d0f9d27355c2baf9c5bf
Author: Andreas Schneider <asn at samba.org>
Date:   Mon Nov 12 15:47:46 2018 +0100

    nsswitch: Handle possible NULL return value of getprogname()
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7a9d003d01adebaf089ca975b04b9d8d4e7640a2
Author: Andreas Schneider <asn at samba.org>
Date:   Mon Nov 12 15:31:09 2018 +0100

    lib:replace: Do not leak the file pointer in rep_getprogname()
    
    And return NULL on error.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 lib/replace/replace.c | 27 +++++++++++++++++----------
 lib/replace/wscript   |  1 +
 nsswitch/wb_common.c  |  9 +++++++--
 3 files changed, 25 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index e38df98ea3a..a14322b8e57 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -980,22 +980,23 @@ int rep_memset_s(void *dest, size_t destsz, int ch, size_t count)
 #endif /* HAVE_MEMSET_S */
 
 #ifndef HAVE_GETPROGNAME
-# ifndef _GNU_SOURCE
+# ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
 # define PROGNAME_SIZE 32
 static char rep_progname[PROGNAME_SIZE];
-# endif /* _GNU_SOURCE */
+# endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
 
 const char *rep_getprogname(void)
 {
-#ifdef _GNU_SOURCE
+#ifdef HAVE_PROGRAM_INVOCATION_SHORT_NAME
 	return program_invocation_short_name;
-#else /* _GNU_SOURCE */
+#else /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
 	FILE *fp = NULL;
 	char cmdline[4096] = {0};
 	char *p = NULL;
 	pid_t pid;
 	size_t nread;
 	int len;
+	int rc;
 
 	if (rep_progname[0] != '\0') {
 		return rep_progname;
@@ -1003,12 +1004,12 @@ const char *rep_getprogname(void)
 
 	len = snprintf(rep_progname, sizeof(rep_progname), "%s", "<unknown>");
 	if (len <= 0) {
-		return "<unknown>";
+		return NULL;
 	}
 
 	pid = getpid();
 	if (pid <= 1 || pid == (pid_t)-1) {
-		return rep_progname;
+		return NULL;
 	}
 
 	len = snprintf(cmdline,
@@ -1016,17 +1017,23 @@ const char *rep_getprogname(void)
 		       "/proc/%u/cmdline",
 		       (unsigned int)pid);
 	if (len <= 0 || len == sizeof(cmdline)) {
-		return rep_progname;
+		return NULL;
 	}
 
 	fp = fopen(cmdline, "r");
 	if (fp == NULL) {
-		return rep_progname;
+		return NULL;
 	}
 
 	nread = fread(cmdline, 1, sizeof(cmdline) - 1, fp);
+
+	rc = fclose(fp);
+	if (rc != 0) {
+		return NULL;
+	}
+
 	if (nread == 0) {
-		return rep_progname;
+		return NULL;
 	}
 
 	cmdline[nread] = '\0';
@@ -1046,6 +1053,6 @@ const char *rep_getprogname(void)
 	(void)snprintf(rep_progname, sizeof(rep_progname), "%s", p);
 
 	return rep_progname;
-#endif /* _GNU_SOURCE */
+#endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
 }
 #endif /* HAVE_GETPROGNAME */
diff --git a/lib/replace/wscript b/lib/replace/wscript
index c8693a3f2e1..ff918146ffa 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -607,6 +607,7 @@ def configure(conf):
 
     conf.CHECK_VARIABLE('rl_event_hook', define='HAVE_DECL_RL_EVENT_HOOK', always=True,
                         headers='readline.h readline/readline.h readline/history.h')
+    conf.CHECK_VARIABLE('program_invocation_short_name', headers='errno.h')
 
     conf.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf')
 
diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
index 6eea32c7e2a..f2672fb1298 100644
--- a/nsswitch/wb_common.c
+++ b/nsswitch/wb_common.c
@@ -89,14 +89,19 @@ void winbind_set_client_name(const char *name)
 static const char *winbind_get_client_name(void)
 {
 	if (client_name[0] == '\0') {
+		const char *progname = getprogname();
 		int len;
 
+		if (progname == NULL) {
+			progname = "<unknown>";
+		}
+
 		len = snprintf(client_name,
 			       sizeof(client_name),
 			       "%s",
-			       getprogname());
+			       progname);
 		if (len <= 0) {
-			return "<unkonwn>";
+			return progname;
 		}
 	}
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list