Accept only digits in NBD device numbers #160

Open
koolkhel wants to merge 2 commits from koolkhel/vitastor:nbd-dev-num-overflow into master

2 Commits

Author SHA1 Message Date
708333820f Check NBD device numbers with a round trip instead of a scanset
Parse the number with strtol and accept it only if std::to_string()
gives back the same text: that refuses signs, spaces, leading zeros and
numbers that overflow int.
2026-11-25 22:49:27 +03:00
2e289d4fc5 Accept only digits in NBD device numbers
sscanf("%d") takes a sign and leading spaces and overflows, so
"vitastor-nbd unmap /dev/nbd+0", "/dev/nbd 0" and /dev/nbd4294967296
all acted on /dev/nbd0: the fallback that #120 removed for mistyped
device names. Parse N and /dev/nbdN only in get_dev_num(), with a
9-digit [0-9] scanset, and keep the positional argument as given.
--dev_num now also accepts /dev/nbdN, the form the error asks for.
2026-11-23 18:07:38 +03:00