]> granicus.if.org Git - strace/commitdiff
Do not copy optarg unnecessarily
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 20 Jul 2017 22:55:57 +0000 (22:55 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 21 Jul 2017 01:30:26 +0000 (01:30 +0000)
There is no need to copy the optarg string since it is a pointer
into the original argv array, not into a static area
that might be overwritten.

* strace.c (username, outfname): Add const qualifier.
(init): Do not xstrdup optarg to initialize outfname and username.

strace.c

index 955a1c9f5e0b2ac42ba01f3a8aee5a2f1c2058a1..c503c3d12da35b3414426537b1732efffd842f89 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -134,7 +134,7 @@ static int exit_code;
 static int strace_child;
 static int strace_tracer_pid;
 
-static char *username;
+static const char *username;
 static uid_t run_uid;
 static gid_t run_gid;
 
@@ -142,7 +142,7 @@ unsigned int max_strlen = DEFAULT_STRLEN;
 static int acolumn = DEFAULT_ACOLUMN;
 static char *acolumn_spaces;
 
-static char *outfname;
+static const char *outfname;
 /* If -ff, points to stderr. Else, it's our common output log */
 static FILE *shared_log;
 
@@ -1727,7 +1727,7 @@ init(int argc, char *argv[])
                        qualify(optarg);
                        break;
                case 'o':
-                       outfname = xstrdup(optarg);
+                       outfname = optarg;
                        break;
                case 'O':
                        i = string_to_uint(optarg);
@@ -1751,7 +1751,7 @@ init(int argc, char *argv[])
                        set_sortby(optarg);
                        break;
                case 'u':
-                       username = xstrdup(optarg);
+                       username = optarg;
                        break;
 #ifdef USE_LIBUNWIND
                case 'k':