From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 06/16] conf, packet: Operands don't affect result, CWE-569 Date: Tue, 05 Apr 2022 19:05:04 +0200 Message-ID: <20220405170514.2963773-7-sbrivio@redhat.com> In-Reply-To: <20220405170514.2963773-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5898621027905652739==" --===============5898621027905652739== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reported by Coverity. Signed-off-by: Stefano Brivio --- conf.c | 7 +++++-- packet.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conf.c b/conf.c index ea51de4..ca44b30 100644 --- a/conf.c +++ b/conf.c @@ -369,6 +369,7 @@ static int conf_ns_opt(struct ctx *c, int ufd =3D -1, nfd =3D -1, try, ret, netns_only_reset =3D c->netns_only; char userns[PATH_MAX] =3D { 0 }, netns[PATH_MAX]; char *endptr; + long pid_arg; pid_t pid; =20 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 =3D 0; try < 3; try++) { if (try =3D=3D 0) { - pid =3D strtol(optarg, &endptr, 10); - if (*endptr || pid > INT_MAX) + pid_arg =3D strtol(optarg, &endptr, 10); + if (*endptr || pid_arg < 0 || pid_arg > INT_MAX) continue; =20 + pid =3D pid_arg; + if (!*conf_userns && !c->netns_only) { ret =3D snprintf(userns, PATH_MAX, "/proc/%i/ns/user", pid); diff --git a/packet.c b/packet.c index fa9e9b4..3358c2c 100644 --- a/packet.c +++ b/packet.c @@ -57,7 +57,7 @@ void packet_add_do(struct pool *p, size_t len, const char *= start, return; } =20 - if ((unsigned int)((intptr_t)start - (intptr_t)p->buf) > UINT32_MAX) { + if ((uint64_t)((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; --=20 2.35.1 --===============5898621027905652739==--