modprobe: protect against possible SEGV
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 26 Jan 2010 07:17:45 +0000 (08:17 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 26 Jan 2010 07:17:45 +0000 (08:17 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
modutils/modprobe.c

index 2860ae0..f339fbd 100644 (file)
@@ -80,12 +80,14 @@ static int read_config(const char *path);
 static char *gather_options_str(char *opts, const char *append)
 {
        /* Speed-optimized. We call gather_options_str many times. */
-       if (opts == NULL) {
-               opts = xstrdup(append);
-       } else {
-               int optlen = strlen(opts);
-               opts = xrealloc(opts, optlen + strlen(append) + 2);
-               sprintf(opts + optlen, " %s", append);
+       if (append) {
+               if (opts == NULL) {
+                       opts = xstrdup(append);
+               } else {
+                       int optlen = strlen(opts);
+                       opts = xrealloc(opts, optlen + strlen(append) + 2);
+                       sprintf(opts + optlen, " %s", append);
+               }
        }
        return opts;
 }