lkml.org 
[lkml]   [2013]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH v2] doc: avoid strncpy in accounting tool
Avoid strncpy anti-pattern. Since optarg is stable, it can be used
directly. This avoids a needless strdup() for the "logfile" variable
as well.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
Fix for -mm clean-up-scary-strncpydst-src-strlensrc-uses-fix.patch
---
Documentation/accounting/getdelays.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index f8ebcde..c402ac0 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -272,7 +272,7 @@ int main(int argc, char *argv[])
char *logfile = NULL;
int loop = 0;
int containerset = 0;
- char containerpath[1024];
+ char *containerpath = NULL;
int cfd = 0;
int forking = 0;
sigset_t sigset;
@@ -299,10 +299,10 @@ int main(int argc, char *argv[])
break;
case 'C':
containerset = 1;
- strncpy(containerpath, optarg, strlen(optarg) + 1);
+ containerpath = optarg;
break;
case 'w':
- logfile = strdup(optarg);
+ logfile = optarg;
printf("write to file %s\n", logfile);
write_file = 1;
break;
--
1.7.9.5

--
Kees Cook
Chrome OS Security


\
 
 \ /
  Last update: 2013-06-06 19:41    [W:0.031 / U:7.424 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site