Bug 99693

Summary: tools: Improve argument validation in dbus-spam
Product: dbus Reporter: Philip Withnall <bugzilla>
Component: coreAssignee: D-Bus Maintainers <dbus>
Status: RESOLVED FIXED QA Contact: D-Bus Maintainers <dbus>
Severity: normal    
Priority: medium CC: bugzilla
Version: unspecifiedKeywords: patch
Hardware: All   
OS: All   
Whiteboard: review+
i915 platform: i915 features:
Attachments: tools: Improve argument validation in dbus-spam
tools: Improve argument validation in dbus-spam

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.