]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxcmd: add return value check for dynamic memory function
authorWeifeng Su <suweifeng1@huawei.com>
Thu, 8 Jun 2023 02:51:46 +0000 (10:51 +0800)
committerCarlos Maiolino <cem@kernel.org>
Wed, 12 Jul 2023 07:15:18 +0000 (09:15 +0200)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxcmd/command.c

index a76d15158eb2de4f1ff2a094a43db0a8a1f003bf..e260309710a466144680d8e047d1260d049ce60b 100644 (file)
@@ -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);
 }