From: Weifeng Su Date: Thu, 8 Jun 2023 02:51:46 +0000 (+0800) Subject: libxcmd: add return value check for dynamic memory function X-Git-Tag: v6.4.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0babf94ff560a53b92586a2fcff88380e9d39893;p=thirdparty%2Fxfsprogs-dev.git libxcmd: add return value check for dynamic memory function The result check was missed and It cause the coredump like: 0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 ) at command.c:37 0x00005589f3e337d8 in init_commands () at init.c:37 init (argc=, argv=0x7ffecfb0cd28) at init.c:102 0x00005589f3e33399 in main (argc=, argv=) at init.c:112 Add check for realloc function to ignore this coredump and exit with error output Signed-off-by: Weifeng Su Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- diff --git a/libxcmd/command.c b/libxcmd/command.c index a76d15158..e26030971 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); }