diff mbox series

[v2] libxcmd: add return value check for dynamic memory function

Message ID 20230608025146.64940-1-suweifeng1@huawei.com (mailing list archive)
State Accepted, archived
Headers show
Series [v2] libxcmd: add return value check for dynamic memory function | expand

Commit Message

Weifeng Su June 8, 2023, 2:51 a.m. UTC
The result check was missed and It cause the coredump like:
0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37
0x00005589f3e337d8 in init_commands () at init.c:37
init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102
0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112

Add check for realloc function to ignore this coredump and exit with
error output

Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
---
Changes since version 1:
- Modify according to review opinions, Add more string 

 libxcmd/command.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Darrick J. Wong June 8, 2023, 2:46 p.m. UTC | #1
On Thu, Jun 08, 2023 at 10:51:46AM +0800, Weifeng Su wrote:
> The result check was missed and It cause the coredump like:
> 0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37
> 0x00005589f3e337d8 in init_commands () at init.c:37
> init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102
> 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112
> 
> Add check for realloc function to ignore this coredump and exit with
> error output
> 
> Signed-off-by: Weifeng Su <suweifeng1@huawei.com>

Looks good to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
> Changes since version 1:
> - Modify according to review opinions, Add more string 
> 
>  libxcmd/command.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libxcmd/command.c b/libxcmd/command.c
> index a76d1515..e2603097 100644
> --- a/libxcmd/command.c
> +++ b/libxcmd/command.c
> @@ -34,6 +34,10 @@ add_command(
>  	const cmdinfo_t	*ci)
>  {
>  	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
> +	if (!cmdtab) {
> +		perror(_("adding libxcmd command"));
> +		exit(1);
> +	}
>  	cmdtab[ncmds - 1] = *ci;
>  	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
>  }
> -- 
> 2.18.0.windows.1
>
Weifeng Su June 12, 2023, 12:23 p.m. UTC | #2
Just ping, Is the merge windown open?

On 2023/6/8 22:46, Darrick J. Wong wrote:
> On Thu, Jun 08, 2023 at 10:51:46AM +0800, Weifeng Su wrote:
>> The result check was missed and It cause the coredump like:
>> 0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37
>> 0x00005589f3e337d8 in init_commands () at init.c:37
>> init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102
>> 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112
>>
>> Add check for realloc function to ignore this coredump and exit with
>> error output
>>
>> Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
> 
> Looks good to me,
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
> --D
> 
>> ---
>> Changes since version 1:
>> - Modify according to review opinions, Add more string
>>
>>   libxcmd/command.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/libxcmd/command.c b/libxcmd/command.c
>> index a76d1515..e2603097 100644
>> --- a/libxcmd/command.c
>> +++ b/libxcmd/command.c
>> @@ -34,6 +34,10 @@ add_command(
>>   	const cmdinfo_t	*ci)
>>   {
>>   	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
>> +	if (!cmdtab) {
>> +		perror(_("adding libxcmd command"));
>> +		exit(1);
>> +	}
>>   	cmdtab[ncmds - 1] = *ci;
>>   	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
>>   }
>> -- 
>> 2.18.0.windows.1
>>
Darrick J. Wong June 12, 2023, 3:25 p.m. UTC | #3
[add xfsprogs maintainer to thread]

On Mon, Jun 12, 2023 at 08:23:00PM +0800, Weifeng Su wrote:
> Just ping, Is the merge windown open?

It's never not open for xfsprogs, but mostly it depends on the xfsprogs
maintainer (Carlos) deciding to pick up a patch.

--D

> On 2023/6/8 22:46, Darrick J. Wong wrote:
> > On Thu, Jun 08, 2023 at 10:51:46AM +0800, Weifeng Su wrote:
> > > The result check was missed and It cause the coredump like:
> > > 0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37
> > > 0x00005589f3e337d8 in init_commands () at init.c:37
> > > init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102
> > > 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112
> > > 
> > > Add check for realloc function to ignore this coredump and exit with
> > > error output
> > > 
> > > Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
> > 
> > Looks good to me,
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> > 
> > --D
> > 
> > > ---
> > > Changes since version 1:
> > > - Modify according to review opinions, Add more string
> > > 
> > >   libxcmd/command.c | 4 ++++
> > >   1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/libxcmd/command.c b/libxcmd/command.c
> > > index a76d1515..e2603097 100644
> > > --- a/libxcmd/command.c
> > > +++ b/libxcmd/command.c
> > > @@ -34,6 +34,10 @@ add_command(
> > >   	const cmdinfo_t	*ci)
> > >   {
> > >   	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
> > > +	if (!cmdtab) {
> > > +		perror(_("adding libxcmd command"));
> > > +		exit(1);
> > > +	}
> > >   	cmdtab[ncmds - 1] = *ci;
> > >   	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
> > >   }
> > > -- 
> > > 2.18.0.windows.1
> > >
Carlos Maiolino June 13, 2023, 7:52 a.m. UTC | #4
On Mon, Jun 12, 2023 at 08:25:33AM -0700, Darrick J. Wong wrote:
> [add xfsprogs maintainer to thread]
> 
> On Mon, Jun 12, 2023 at 08:23:00PM +0800, Weifeng Su wrote:
> > Just ping, Is the merge windown open?
> 
> It's never not open for xfsprogs, but mostly it depends on the xfsprogs
> maintainer (Carlos) deciding to pick up a patch.

I'll pull this into for-next on my next batch. Hopefully this week yet.
diff mbox series

Patch

diff --git a/libxcmd/command.c b/libxcmd/command.c
index a76d1515..e2603097 100644
--- a/libxcmd/command.c
+++ b/libxcmd/command.c
@@ -34,6 +34,10 @@  add_command(
 	const cmdinfo_t	*ci)
 {
 	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+	if (!cmdtab) {
+		perror(_("adding libxcmd command"));
+		exit(1);
+	}
 	cmdtab[ncmds - 1] = *ci;
 	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
 }