Re: [PATCH v2] trace-cmd: Check all strdup() return values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 3 Jun 2023 08:12:34 +0200
Markus Elfring <Markus.Elfring@xxxxxx> wrote:

>
> > +++ b/lib/trace-cmd/trace-input.c  
>
> > @@ -5967,9 +5974,10 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx)
> >  	new_handle->parent = handle;
> >  	new_handle->cpustats = NULL;
> >  	new_handle->hooks = NULL;
> > -	if (handle->uname)
> > +	if (handle->uname) {
> >  		/* Ignore if fails to malloc, no biggy */
> >  		new_handle->uname = strdup(handle->uname);
> > +	}
> >  	tracecmd_ref(handle);
> >
> >  	new_handle->fd = dup(handle->fd);  
> 
> Does this return value ignorance need a bit more explanation?

Yes that should be checked.

> 
> 
>
> > +++ b/tracecmd/trace-record.c  
>
> > @@ -6651,6 +6658,8 @@ static void parse_record_options(int argc,
> >  		case OPT_tsoffset:
> >  			cmd_check_die(ctx, CMD_set, *(argv+1), "--ts-offset");
> >  			ctx->date2ts = strdup(optarg);
> > +			if (ctx->date2ts == NULL)
> > +				die("Faield to allocate ts-offset");
> >  			if (ctx->data_flags & DATA_FL_DATE)
> >  				die("Can not use both --date and --ts-offset");
> >  			ctx->data_flags |= DATA_FL_OFFSET;
> > @@ -6712,6 +6721,8 @@ static void parse_record_options(int argc,
> >  			    !tracecmd_compress_is_supported(optarg, NULL))
> >  				die("Compression algorithm  %s is not supported", optarg);
> >  			ctx->compression = strdup(optarg);
> > +			if (ctx->compression == NULL)
> > +				die("Faield to allocate compression algorithm");
> >  			break;
> >  		case OPT_file_ver:
> >  			if (ctx->curr_cmd != CMD_record && ctx->curr_cmd != CMD_record_agent)  
>
> > +++ b/tracecmd/trace-split.c
> > @@ -367,6 +367,8 @@ static double parse_file(struct tracecmd_input *handle,
> >  	int fd;
> >
> >  	output = strdup(output_file);
> > +	if (output == NULL)
> > +		die("Faield to allocate output_file");
> >  	dir = dirname(output);
> >  	base = basename(output);
> >  
>
> 
> I recommend to avoid typos also in error messages.

Heh, I'm pushing hard to get the trivial changes in so that I can start
working on some more substantial changes, and in the rush, I did make
some bad spelling mistakes. I will fix.

Thanks,

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux