chiark / gitweb /
[PATCH] PATCH some cleanups and security fixes
[elogind.git] / namedev.c
index 466016c297972c46afef90aa964df47adb357a63..c8217024c87070e20a953269105440bf1853d07a 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -433,9 +433,9 @@ static int execute_program(char *path, char *value, int len)
                                /* don't separate if in apostrophes */
                                pos++;
                                argv[i] = strsep(&pos, "\'");
-                               while (pos[0] == ' ')
+                               while (pos && pos[0] == ' ')
                                        pos++;
-               } else {
+                       } else {
                                argv[i] = strsep(&pos, " ");
                        }
                        dbg("arg[%i] '%s'", i, argv[i]);
@@ -813,10 +813,12 @@ static int match_rule(struct config_device *dev, struct sysfs_class_device *clas
 
                /* execute external program */
                if (dev->program[0] != '\0') {
+                       char program[PROGRAM_SIZE];
+
                        dbg("check " FIELD_PROGRAM);
-                       apply_format(udev, dev->program, sizeof(dev->program),
-                                    class_dev, sysfs_device);
-                       if (execute_program(dev->program, udev->program_result, NAME_SIZE) != 0) {
+                       strfieldcpy(program, dev->program);
+                       apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
+                       if (execute_program(program, udev->program_result, NAME_SIZE) != 0) {
                                dbg(FIELD_PROGRAM " returned nonzero");
                                goto try_parent;
                        } else {