Skip to content

Commit

Permalink
Fix possible NULL deref when looking for PCP dynamic columns
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Jan 22, 2025
1 parent 3a9f468 commit 53f7e63
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions pcp/PCPDynamicScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,40 @@ static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen,
}

static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* path, unsigned int line, char* key, char* value) {
PCPDynamicColumn* column;
char* p;

if ((p = strchr(key, '.')) == NULL)
char* p = strchr(key, '.');
if (!p) {
return;
}

*p++ = '\0'; /* end the name, p is now the attribute, e.g. 'label' */

/* lookup a dynamic column with this name, else create */
column = PCPDynamicScreen_lookupMetric(screen, key);
PCPDynamicColumn* column = PCPDynamicScreen_lookupMetric(screen, key);
if (!column) {
return;
}

if (String_eq(p, "metric")) {
char* error;
char* error = NULL;
if (pmRegisterDerivedMetric(column->metricName, value, &error) < 0) {
char* note;
xAsprintf(&note,
"%s: failed to parse expression in %s at line %u\n%s\n",
pmGetProgname(), path, line, error);
free(error);
char* note = NULL;
xAsprintf(
&note,
"%s: failed to parse expression in %s at line %u\n%s\n",
pmGetProgname(), path, line, error
);

errno = EINVAL;
CRT_fatalError(note);
free(note);

free(error);
}

/* pmLookupText - add optional metric help text */
if (!column->super.description && !column->instances)
if (!column->super.description && !column->instances) {
Metric_lookupText(value, &column->super.description);

}
} else {
/* this is a property of a dynamic column - the column expression */
/* may not have been observed yet; i.e. we allow for any ordering */
Expand All @@ -145,12 +152,16 @@ static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* p
} else if (String_eq(p, "format")) {
free_and_xStrdup(&column->format, value);
} else if (String_eq(p, "instances")) {
if (String_eq(value, "True") || String_eq(value, "true"))
column->instances = false;
if (String_eq(value, "True") || String_eq(value, "true")) {
column->instances = true;
}
free_and_xStrdup(&column->super.description, screen->super.caption);
} else if (String_eq(p, "default")) { /* displayed by default */
if (String_eq(value, "False") || String_eq(value, "false"))
column->defaultEnabled = column->super.enabled = true;
if (String_eq(value, "False") || String_eq(value, "false")) {
column->defaultEnabled = column->super.enabled = false;
}
}
}
}
Expand Down

0 comments on commit 53f7e63

Please sign in to comment.