Re: [PATCH v3] blkparse: Fix a potential coredump issue

Jens Axboe <[email protected]> Wed, 19 Mar 2025 07:10:58 -0600
Newsgroups org.kernel.vger.linux-btrace
Message-ID <[email protected]>
On 3/19/25 7:02 AM, [email protected] wrote:
> diff --git a/blkparse.c b/blkparse.c
> index 9d2029a..d6aaa8b 100644
> --- a/blkparse.c
> +++ b/blkparse.c
> @@ -1022,7 +1022,7 @@ static struct io_track *find_track(struct per_dev_info *pdi, pid_t pid,
>  	if (!iot) {
>  		struct io_track_req *req;
>  
> -		req = malloc(sizeof(*req) + sizeof(*iot));
> +		req = calloc(1, sizeof(*req) + sizeof(*iot));
>  		req->ppm = find_ppm(pid);
>  		if (!req->ppm)
>  			req->ppm = add_ppm_hash(pid, "unknown");
> @@ -1106,7 +1106,7 @@ static void log_track_split(struct per_dev_info *pdi, struct blk_io_trace *t)
>  	 * parts.
>  	 */
>  	iot = find_track(pdi, t->pid, t->sector);
> -	split = malloc(sizeof(*iot));
> +	split = calloc(1, sizeof(*iot));
>  	split->req = iot->req;
>  	split->next = iot->next;
>  	iot->next = split;

Nit picking, but the idiomatic way would be to make it calloc(size, 1)
not the other way around. The first one is the size, the 2nd one is the
number of them.

-- 
Jens Axboe