[PATCH] printflags: handle empty xlats

Dmitry V. Levin ldv at altlinux.org
Sat Oct 31 14:05:58 UTC 2015


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.


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


More information about the Strace-devel mailing list