Only fill in subsystem_ids[] for the instance if the caller passed

in an array for it.  If the caller only wants the default subsystems
we don't actually need ids[].
This commit is contained in:
Todd C. Miller
2014-10-23 13:19:51 -06:00
parent f2eb6dcc06
commit 2a47abad21

View File

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