Bug 99693 - tools: Improve argument validation in dbus-spam
Summary: tools: Improve argument validation in dbus-spam
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: D-Bus Maintainers
QA Contact: D-Bus Maintainers
URL:
Whiteboard: review+
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-02-06 13:03 UTC by Philip Withnall
Modified: 2017-02-13 15:58 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
tools: Improve argument validation in dbus-spam (1.27 KB, patch)
2017-02-06 13:03 UTC, Philip Withnall
Details | Splinter Review
tools: Improve argument validation in dbus-spam (1.27 KB, patch)
2017-02-07 15:03 UTC, Philip Withnall
Details | Splinter Review

Description Philip Withnall 2017-02-06 13:03:42 UTC
Trivial patch attached.
Comment 1 Philip Withnall 2017-02-06 13:03:45 UTC
Created attachment 129362 [details] [review]
tools: Improve argument validation in dbus-spam

Check that at most one argument which sets the payload is provided, so
the allocated payload is not overwritten and leaked.

Coverity ID: 54759

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Simon McVittie 2017-02-07 11:00:05 UTC
Comment on attachment 129362 [details] [review]
tools: Improve argument validation in dbus-spam

Review of attachment 129362 [details] [review]:
-----------------------------------------------------------------

::: tools/dbus-spam.c
@@ +186,5 @@
> +           strcmp (arg, "--random-size") == 0))
> +        {
> +          fprintf (stderr, "At most one of --payload, --stdin, --message-stdin "
> +                           "and --random-size may be specified\n");
> +          exit (1);

I'd slightly prefer exit status 2, which I believe is semi-common for distinguishing invalid arguments from a functional failure (for instance it's what Python argparse uses) and is consistently used in this tool.

I'd slightly prefer printing usage: usage (2); which again is consistently used in this tool.
Comment 3 Philip Withnall 2017-02-07 11:58:46 UTC
(In reply to Simon McVittie from comment #2)
> Comment on attachment 129362 [details] [review] [review]
> tools: Improve argument validation in dbus-spam
> 
> Review of attachment 129362 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: tools/dbus-spam.c
> @@ +186,5 @@
> > +           strcmp (arg, "--random-size") == 0))
> > +        {
> > +          fprintf (stderr, "At most one of --payload, --stdin, --message-stdin "
> > +                           "and --random-size may be specified\n");
> > +          exit (1);
> 
> I'd slightly prefer exit status 2, which I believe is semi-common for
> distinguishing invalid arguments from a functional failure (for instance
> it's what Python argparse uses) and is consistently used in this tool.

Ah, yes.

> I'd slightly prefer printing usage: usage (2); which again is consistently
> used in this tool.

And dropping the specific error message, or printing usage(2) in addition to it?
Comment 4 Simon McVittie 2017-02-07 14:14:10 UTC
(In reply to Philip Withnall from comment #3)
> > I'd slightly prefer printing usage: usage (2); which again is consistently
> > used in this tool.
> 
> And dropping the specific error message, or printing usage(2) in addition to
> it?

I meant in addition. (But if you think the result looks stupid, just print the specific message and exit 2.)
Comment 5 Philip Withnall 2017-02-07 15:03:49 UTC
Created attachment 129389 [details] [review]
tools: Improve argument validation in dbus-spam

Check that at most one argument which sets the payload is provided, so
the allocated payload is not overwritten and leaked.

Coverity ID: 54759

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 6 Simon McVittie 2017-02-07 19:29:54 UTC
Looks good, thanks. Will be in my next batch of applying patches.
Comment 7 Simon McVittie 2017-02-13 15:58:21 UTC
Fixed in git for 1.11.10, thanks


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.