summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Small <csmall@enc.com.au>2016-04-27 22:50:25 +1000
committerCraig Small <csmall@enc.com.au>2016-04-27 22:50:25 +1000
commitad13b4badb552a73e414b1e6aab06b1c24fcc8a4 (patch)
tree8ca334fbd8011220ab124e6405a7f38741868d35
parentf6d6d305e762a24b4d6ca18771174fd6240da99d (diff)
downloadprocps-ng-ad13b4badb552a73e414b1e6aab06b1c24fcc8a4.tar.gz
pgrep: some coverity fixes
procps_ns_get_id should be checked for < 0 not -1 strncpy should copy only to buflen-1 not buflen References: Coverity 99117, 99108, 99107
-rw-r--r--.gitignore1
-rw-r--r--pgrep.c12
2 files changed, 7 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 5b27ad8..4333f54 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ config.rpath
config.status
config.sub
configure
+cov-int
depcomp
free
INSTALL
diff --git a/pgrep.c b/pgrep.c
index 85e703a..dc78287 100644
--- a/pgrep.c
+++ b/pgrep.c
@@ -264,7 +264,7 @@ static struct el *read_pidfile(void)
if (n<1)
goto out;
pid = strtoul(buf+1,&endp,10);
- if(endp<=buf+1 || pid<1 || pid>0x7fffffff)
+ if(endp<=buf+1 || pid<1 )
goto out;
if(*endp && !isspace(*endp))
goto out;
@@ -359,7 +359,7 @@ static int conv_ns (const char *restrict name, struct el *restrict e)
ns_flags = 0;
id = procps_ns_get_id(name);
- if (id == -1)
+ if (id < 0)
return 0;
ns_flags |= (1 << id);
@@ -545,16 +545,16 @@ static struct el * select_procs (int *num)
if (opt_long || opt_longlong || (match && opt_pattern)) {
if (opt_longlong)
- strncpy (cmdoutput, task_cmdline, CMDSTRSIZE);
+ strncpy (cmdoutput, task_cmdline, CMDSTRSIZE-1);
else
- strncpy (cmdoutput, PIDS_GETSTR(CMD), CMDSTRSIZE);
+ strncpy (cmdoutput, PIDS_GETSTR(CMD), CMDSTRSIZE-1);
}
if (match && opt_pattern) {
if (opt_full)
- strncpy (cmdsearch, task_cmdline, CMDSTRSIZE);
+ strncpy (cmdsearch, task_cmdline, CMDSTRSIZE-1);
else
- strncpy (cmdsearch, PIDS_GETSTR(CMD), CMDSTRSIZE);
+ strncpy (cmdsearch, PIDS_GETSTR(CMD), CMDSTRSIZE-1);
if (regexec (preg, cmdsearch, 0, NULL, 0) != 0)
match = 0;