server: public: Add nbdkit_parse_* functions for safely parsing integers.
commitc4c89d697236cf791ba8527a713bc8635a030e3b
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 21 Sep 2019 06:30:40 +0000 (21 07:30 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 23 Sep 2019 21:40:49 +0000 (23 22:40 +0100)
treee48b42cbdd0ec8fc28b805b2fa5deac90c3c355e
parent0b8efde4fed62e34a67dc165c4dceb7d737bff26
server: public: Add nbdkit_parse_* functions for safely parsing integers.

sscanf is sadly not safe (because it doesn't handle integer overflow
correctly), and strto*l functions are a pain to use correctly.
Therefore add some functions to hide the pain of parsing integers from
the command line.

The simpler uses of sscanf and strto*l are replaced.  There are still
a few where we are using advanced features of sscanf.

This changes command line parsing in some corner cases:

* For some parameters you might have written (eg)
  ‘cache-high-threshold=08’ to mean decimal 8, but now it would be a
  parse error.  ‘cache-high-threshold=010’ would previously have
  parsed as decimal 10, but would now parse as octal 10 (decimal 8).

* Some parameters previously accepted a wider range of values.  Now
  they will give an error, but the narrower range accepted should
  always be more correct.

Thanks: Eric Blake
23 files changed:
docs/nbdkit-plugin.pod
filters/cache/cache.c
filters/cache/cache.h
filters/partition/partition.c
filters/partition/partition.h
filters/retry/retry.c
filters/xz/xz.c
include/nbdkit-common.h
plugins/curl/curl.c
plugins/nbd/nbd-standalone.c
plugins/nbd/nbd.c
plugins/partitioning/partitioning.c
plugins/partitioning/virtual-disk.h
plugins/random/random.c
plugins/ssh/ssh.c
plugins/vddk/vddk.c
server/internal.h
server/main.c
server/nbdkit.syms
server/public.c
server/socket-activation.c
server/test-public.c
server/usergroup.c