Skip to content
Browse files

Fix: fencing: Prevent invalid read in parse_host_list()

  • Loading branch information...
1 parent 2253fc3 commit c637bf7098d5b14cd9aca0006c2fd4d600788def @beekhof committed Mar 21, 2013
Showing with 9 additions and 9 deletions.
  1. +9 −9 fencing/commands.c
View
18 fencing/commands.c
@@ -407,15 +407,12 @@ build_port_aliases(const char *hostmap, GListPtr * targets)
}
static void
-parse_host_line(const char *line, GListPtr * output)
+parse_host_line(const char *line, int max, GListPtr * output)
{
int lpc = 0;
- int max = 0;
int last = 0;
- if (line) {
- max = strlen(line);
- } else {
+ if (max <= 0) {
return;
}
@@ -425,7 +422,7 @@ parse_host_line(const char *line, GListPtr * output)
return;
}
- crm_trace("Processing: [%s]", line);
+ crm_trace("Processing %d bytes: [%s]", max, line);
/* Skip initial whitespace */
for (lpc = 0; lpc <= max && isspace(line[lpc]); lpc++) {
last = lpc + 1;
@@ -482,17 +479,18 @@ parse_host_list(const char *hosts)
int len = lpc - last;
if(len > 1) {
- line = calloc(1, 2 + len);
+ line = malloc(1 + len);
snprintf(line, 1 + len, "%s", hosts + last);
- line[len] = 0;
- parse_host_line(line, &output);
+ line[len] = 0; /* Because it might be '\n' */
+ parse_host_line(line, len, &output);
free(line);
}
last = lpc + 1;
}
}
+ crm_trace("Parsed %d entries from '%s'", g_list_length(output), hosts);
return output;
}
@@ -690,6 +688,8 @@ string_in_list(GListPtr list, const char *item)
if (safe_str_eq(item, value)) {
return TRUE;
+ } else {
+ crm_trace("%d: '%s' != '%s'", lpc, item, value);
}
}
return FALSE;

0 comments on commit c637bf7

Please sign in to comment.
Something went wrong with that request. Please try again.