aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-06-28 15:11:14 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-06-28 17:51:11 +0200
commitc4017cc4a16b1b7d1854498ba64ed27e5a3d0555 (patch)
treece1b33d6e0763b7e10e7eed1e942f4667213125e /conf.c
parent289301b39c40dfb9f48f54d9848fbc19a17523ba (diff)
downloadpasst-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar.gz
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar.bz2
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar.lz
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar.xz
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.tar.zst
passt-c4017cc4a16b1b7d1854498ba64ed27e5a3d0555.zip
conf: Fix size checking of -I interface name
Network interface names must fit in a buffer of IFNAMSIZ bytes, including the terminating \0. IFNAMSIZ is 16 on Linux, so interface names can be up to (and including) 15 characters long. We validate this for the -I option, but we have an off by one error. We pass (IFNAMSIZ - 1) as the buffer size to snprintf(), but that buffer size already includes the terminating \0, so this actually truncates the value to 14 characters. The return value returned from snprintf() however, is the number of characters that would have been printed *excluding* the terminating \0, so by comparing it >= IFNAMSIZ - 1 we are giving an error on names >= 15 characters rather than strictly > 15 characters. Link: https://bugs.passt.top/show_bug.cgi?id=61 Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/conf.c b/conf.c
index 68487a4..1906436 100644
--- a/conf.c
+++ b/conf.c
@@ -1439,9 +1439,9 @@ void conf(struct ctx *c, int argc, char **argv)
if (*c->pasta_ifn)
die("Multiple --ns-ifname options given");
- ret = snprintf(c->pasta_ifn, IFNAMSIZ - 1, "%s",
+ ret = snprintf(c->pasta_ifn, IFNAMSIZ, "%s",
optarg);
- if (ret <= 0 || ret >= IFNAMSIZ - 1)
+ if (ret <= 0 || ret >= IFNAMSIZ)
die("Invalid interface name: %s", optarg);
break;