mirror of
https://passt.top/passt
synced 2025-07-27 19:58:00 +02:00
conf: More thorough error checking when parsing --mtu option
We're a bit sloppy with parsing MTU which can lead to some surprising, though fairly harmless, results: * Passing a non-number like '-m xyz' will not give an error and act like -m 0 * Junk after a number (e.g. '-m 1500pqr') will be ignored rather than giving an error * We parse the MTU as a long, then immediately assign to an int, so on some platforms certain ludicrously out of bounds values will be silently truncated, rather than giving an error Be a bit more thorough with the error checking to avoid that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
65e317a8fc
commit
3dc7da68a2
1 changed files with 16 additions and 7 deletions
23
conf.c
23
conf.c
|
@ -1652,20 +1652,29 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||||
die("Invalid PID file: %s", optarg);
|
die("Invalid PID file: %s", optarg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm': {
|
||||||
errno = 0;
|
unsigned long mtu;
|
||||||
c->mtu = strtol(optarg, NULL, 0);
|
char *e;
|
||||||
|
|
||||||
if (!c->mtu) {
|
errno = 0;
|
||||||
|
mtu = strtoul(optarg, &e, 0);
|
||||||
|
|
||||||
|
if (errno || *e)
|
||||||
|
die("Invalid MTU: %s", optarg);
|
||||||
|
|
||||||
|
if (!mtu) {
|
||||||
c->mtu = -1;
|
c->mtu = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->mtu < ETH_MIN_MTU || c->mtu > (int)ETH_MAX_MTU ||
|
if (mtu < ETH_MIN_MTU || mtu > ETH_MAX_MTU) {
|
||||||
errno)
|
die("MTU %lu out of range (%u..%u)", mtu,
|
||||||
die("Invalid MTU: %s", optarg);
|
ETH_MIN_MTU, ETH_MAX_MTU);
|
||||||
|
}
|
||||||
|
|
||||||
|
c->mtu = mtu;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'a':
|
case 'a':
|
||||||
if (inet_pton(AF_INET6, optarg, &c->ip6.addr) &&
|
if (inet_pton(AF_INET6, optarg, &c->ip6.addr) &&
|
||||||
!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr) &&
|
!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr) &&
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue