s3/lib/popt_common: use stack buffer in set_logfile()
authorDavid Disseldorp <ddiss@samba.org>
Wed, 6 Feb 2019 11:01:12 +0000 (12:01 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Thu, 7 Feb 2019 16:23:18 +0000 (17:23 +0100)
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/lib/popt_common.c

index 7f9bc389e83d92763b9be3546e47369deca57fe2..fa21668000e6816750c2457b9cfca26fa0ff430e 100644 (file)
@@ -42,22 +42,23 @@ extern bool override_logfile;
 static void set_logfile(poptContext con, const char * arg)
 {
 
-       char *lfile = NULL;
+       char lfile[PATH_MAX];
        const char *pname;
+       int ret;
 
        /* Find out basename of current program */
-       pname = strrchr_m(poptGetInvocationName(con),'/');
-
-       if (!pname)
+       pname = strrchr_m(poptGetInvocationName(con), '/');
+       if (pname == NULL) {
                pname = poptGetInvocationName(con);
-       else
+       } else {
                pname++;
+       }
 
-       if (asprintf(&lfile, "%s/log.%s", arg, pname) < 0) {
+       ret = snprintf(lfile, sizeof(lfile), "%s/log.%s", arg, pname);
+       if (ret >= sizeof(lfile)) {
                return;
        }
        lp_set_logfile(lfile);
-       SAFE_FREE(lfile);
 }
 
 static bool PrintSambaVersionString;