udhcpc: fix a problem with binary-encoded options #2
[oweals/busybox.git] / modutils / modutils-24.c
index 2b34954c0f269bce4c8834ab85434e59817a308c..12cb75c54c845915e398bfd0f0d8ddc04af6ec9c 100644 (file)
@@ -60,7 +60,6 @@
 
 #include "libbb.h"
 #include "modutils.h"
-#include <libgen.h>
 #include <sys/utsname.h>
 
 #if ENABLE_FEATURE_INSMOD_LOADINKMEM
@@ -2444,14 +2443,12 @@ new_process_module_arguments(struct obj_file *f, const char *options)
                        bb_error_msg_and_die("symbol for parameter %s not found", param);
 
                /* Number of parameters */
+               min = max = 1;
                if (isdigit(*pinfo)) {
-                       min = strtoul(pinfo, &pinfo, 10);
+                       min = max = strtoul(pinfo, &pinfo, 10);
                        if (*pinfo == '-')
                                max = strtoul(pinfo + 1, &pinfo, 10);
-                       else
-                               max = min;
-               } else
-                       min = max = 1;
+               }
 
                contents = f->sections[sym->secidx]->contents;
                loc = contents + sym->value;
@@ -2473,7 +2470,8 @@ new_process_module_arguments(struct obj_file *f, const char *options)
                /* Parse parameter values */
                n = 0;
                p = val;
-               while (*p != 0) {
+               while (*p) {
+                       char sv_ch;
                        char *endp;
 
                        if (++n > max)
@@ -2482,21 +2480,25 @@ new_process_module_arguments(struct obj_file *f, const char *options)
                        switch (*pinfo) {
                        case 's':
                                len = strcspn(p, ",");
-                               p[len] = 0;
+                               sv_ch = p[len];
+                               p[len] = '\0';
                                obj_string_patch(f, sym->secidx,
                                                 loc - contents, p);
                                loc += tgt_sizeof_char_p;
                                p += len;
+                               *p = sv_ch;
                                break;
                        case 'c':
                                len = strcspn(p, ",");
-                               p[len] = 0;
+                               sv_ch = p[len];
+                               p[len] = '\0';
                                if (len >= charssize)
                                        bb_error_msg_and_die("string too long for %s (max %ld)", param,
                                                             charssize - 1);
                                strcpy((char *) loc, p);
                                loc += charssize;
                                p += len;
+                               *p = sv_ch;
                                break;
                        case 'b':
                                *loc++ = strtoul(p, &endp, 0);