[libvirt] [PATCH 02/10] Replace sscanf in nwfilter rule parsing

Jim Meyering jim at meyering.net
Tue Mar 30 17:11:40 UTC 2010


Matthias Bolte wrote:
>  src/conf/nwfilter_conf.c |   10 +++++-----


Hi Matthias,

It's great that you're removing all of these sscanf uses.
I suppose the plan includes eventually enabling the syntax-check
that prohibits them altogether.

> diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
> @@ -1226,7 +1226,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn ATTRIBUTE_UNUSED,
> -                            if (sscanf(prop, "%d", &int_val) == 1) {
> +                            if (virStrToLong_i(prop, NULL, 10, &int_val) >= 0) {

Not sure it's worth worrying about, but bear in mind
that this patch does induce a semantic change:
sscanf is more permissive, and returns "1" even if there's
garbage in the "prop" string after a valid integer, while
virStrToLong_i (with NULL param #2) will reject that same
bogus input string.

I think of this as a feature, but it probably deserves
a note in the commit log, so if some libvirt client starts
seeing mysterious new failures due to their previously-accepted
bogus inputs, they might find this set of commits.

Other than that, this patch looks fine.




More information about the libvir-list mailing list