conf, packet: Operands don't affect result, CWE-569

Reported by Coverity.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2022-04-05 07:24:48 +02:00
parent 48bc843d6e
commit 0786b2e60a
2 changed files with 8 additions and 3 deletions

7
conf.c
View file

@ -369,6 +369,7 @@ static int conf_ns_opt(struct ctx *c,
int ufd = -1, nfd = -1, try, ret, netns_only_reset = c->netns_only;
char userns[PATH_MAX] = { 0 }, netns[PATH_MAX];
char *endptr;
long pid_arg;
pid_t pid;
if (c->netns_only && *conf_userns) {
@ -379,10 +380,12 @@ static int conf_ns_opt(struct ctx *c,
/* It might be a PID, a netns path, or a netns name */
for (try = 0; try < 3; try++) {
if (try == 0) {
pid = strtol(optarg, &endptr, 10);
if (*endptr || pid > INT_MAX)
pid_arg = strtol(optarg, &endptr, 10);
if (*endptr || pid_arg < 0 || pid_arg > INT_MAX)
continue;
pid = pid_arg;
if (!*conf_userns && !c->netns_only) {
ret = snprintf(userns, PATH_MAX,
"/proc/%i/ns/user", pid);

View file

@ -57,11 +57,13 @@ void packet_add_do(struct pool *p, size_t len, const char *start,
return;
}
if ((unsigned int)((intptr_t)start - (intptr_t)p->buf) > UINT32_MAX) {
#if UINTPTR_MAX == UINT64_MAX
if ((uintptr_t)start - (uintptr_t)p->buf > UINT32_MAX) {
trace("add packet start %p, buffer start %p, %s:%i",
start, p->buf, func, line);
return;
}
#endif
p->pkt[index].offset = start - p->buf;
p->pkt[index].len = len;