Whamcloud - gitweb
libss: handle memory allcation failure in ss_help()
authorLukas Czerner <lczerner@redhat.com>
Fri, 6 Aug 2021 09:58:18 +0000 (11:58 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 10 Aug 2021 15:02:57 +0000 (11:02 -0400)
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ss/help.c

index 96eb109..a22b401 100644 (file)
@@ -96,7 +96,12 @@ void ss_help(int argc, char const * const *argv, int sci_idx, pointer info_ptr)
     }
     if (fd < 0) {
 #define MSG "No info found for "
-        char *buf = malloc(strlen (MSG) + strlen (argv[1]) + 1);
+       char *buf = malloc(strlen (MSG) + strlen (argv[1]) + 1);
+       if (!buf) {
+               ss_perror(sci_idx, 0,
+                         "couldn't allocate memory to print error message");
+               return;
+       }
        strcpy(buf, MSG);
        strcat(buf, argv[1]);
        ss_perror(sci_idx, 0, buf);