]> granicus.if.org Git - sudo/commitdiff
Only fill in subsystem_ids[] for the instance if the caller passed
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 23 Oct 2014 19:19:51 +0000 (13:19 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 23 Oct 2014 19:19:51 +0000 (13:19 -0600)
in an array for it.  If the caller only wants the default subsystems
we don't actually need ids[].

lib/util/sudo_debug.c

index 24325978fa570fba1a3f0868b408438a557cc1ec..46f409804bf52c399a17e909dbb7fe810b271f0e 100644 (file)
@@ -197,12 +197,14 @@ sudo_debug_new_output(struct sudo_debug_instance *instance,
            if (strcasecmp(pri, sudo_debug_priorities[i]) == 0) {
                for (j = 0; instance->subsystems[j] != NULL; j++) {
                    if (strcasecmp(subsys, "all") == 0) {
-                       const int idx = SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]);
+                       const idx = instance->subsystem_ids ?
+                           SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j;
                        output->settings[idx] = i;
                        continue;
                    }
                    if (strcasecmp(subsys, instance->subsystems[j]) == 0) {
-                       const int idx = SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]);
+                       const idx = instance->subsystem_ids ?
+                           SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j;
                        output->settings[idx] = i;
                        break;
                    }
@@ -259,16 +261,18 @@ sudo_debug_register(const char *program, const char *const subsystems[],
     if (instance == NULL) {
        unsigned int i, j, max_id = NUM_DEF_SUBSYSTEMS - 1;
 
-       /* Fill in subsystem name -> id mapping. */
-       for (i = 0; subsystems[i] != NULL; i++) {
-           /* Check default subsystems. */
-           for (j = 0; j < NUM_DEF_SUBSYSTEMS; j++) {
-               if (strcmp(subsystems[i], sudo_debug_default_subsystems[j]) == 0)
-                   break;
+       /* Fill in subsystem name -> id mapping as needed. */
+       if (ids != NULL) {
+           for (i = 0; subsystems[i] != NULL; i++) {
+               /* Check default subsystems. */
+               for (j = 0; j < NUM_DEF_SUBSYSTEMS; j++) {
+                   if (strcmp(subsystems[i], sudo_debug_default_subsystems[j]) == 0)
+                       break;
+               }
+               if (j == NUM_DEF_SUBSYSTEMS)
+                   j = ++max_id;
+               ids[i] = ((j + 1) << 16);
            }
-           if (j == NUM_DEF_SUBSYSTEMS)
-               j = ++max_id;
-           ids[i] = ((j + 1) << 16);
        }
 
        if (free_idx != -1)