[PATCH] printflags: handle empty xlats

Dmitry V. Levin ldv at altlinux.org
Sun Nov 15 22:23:07 UTC 2015


On Sat, Oct 31, 2015 at 05:05:58PM +0300, Dmitry V. Levin wrote:
> On Sat, Oct 31, 2015 at 12:47:59AM -0400, Mike Frysinger wrote:
> > If the set of headers are unable to produce a valid list, printflags
> > will try to pass NULL to tprints which crashes.  Add a sanity check
> > for this edge case.
> > 
> > * util.c (printflags): Check xlat->str is not NULL.
> > ---
> >  util.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/util.c b/util.c
> > index c3e3fda..7c19044 100644
> > --- a/util.c
> > +++ b/util.c
> > @@ -353,8 +353,11 @@ printflags(const struct xlat *xlat, int flags, const char *dflt)
> >  	const char *sep;
> >  
> >  	if (flags == 0 && xlat->val == 0) {
> > -		tprints(xlat->str);
> > -		return 1;
> > +		if (xlat->str) {
> > +			tprints(xlat->str);
> > +			return 1;
> > +		} else
> > +			return 0;
> >  	}
> 
> Since callers expect that printflags will print something if dflt != NULL,
> I'd suggest adding xlat->str test right to the first condition instead.

I'm going to push the following edition of your fix, if you don't mind.

--- a/util.c
+++ b/util.c
@@ -357,7 +357,7 @@ printflags(const struct xlat *xlat, int flags, const char *dflt)
 	int n;
 	const char *sep;
 
-	if (flags == 0 && xlat->val == 0) {
+	if (flags == 0 && xlat->val == 0 && xlat->str) {
 		tprints(xlat->str);
 		return 1;
 	}

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20151116/a709775d/attachment.bin>


More information about the Strace-devel mailing list