mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
libdm: add missing error handling in _stats_parse_histogram()
Since we are growing an object in the histogram pool the return value of dm_pool_grow_object() must be checked and error paths need to abandon the object before returning.
This commit is contained in:
parent
a26523330e
commit
36b09fd147
@ -721,22 +721,20 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
|
|
||||||
hist.nr_bins = nr_bins;
|
hist.nr_bins = nr_bins;
|
||||||
|
|
||||||
dm_pool_grow_object(mem, &hist, sizeof(hist));
|
if (!dm_pool_grow_object(mem, &hist, sizeof(hist)))
|
||||||
|
goto_bad;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
memset(&cur, 0, sizeof(cur));
|
memset(&cur, 0, sizeof(cur));
|
||||||
for (v = _valid_chars; *v; v++)
|
for (v = _valid_chars; *v; v++)
|
||||||
if (*c == *v)
|
if (*c == *v)
|
||||||
break;
|
break;
|
||||||
if (!*v) {
|
if (!*v)
|
||||||
stack;
|
|
||||||
goto badchar;
|
goto badchar;
|
||||||
}
|
|
||||||
|
|
||||||
if (*c == ',') {
|
if (*c == ',')
|
||||||
log_error("Invalid histogram: %s", hist_str);
|
goto badchar;
|
||||||
return 0;
|
else {
|
||||||
} else {
|
|
||||||
const char *val_start = c;
|
const char *val_start = c;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
uint64_t this_val = 0;
|
uint64_t this_val = 0;
|
||||||
@ -744,17 +742,15 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
this_val = strtoull(val_start, &endptr, 10);
|
this_val = strtoull(val_start, &endptr, 10);
|
||||||
if (!endptr) {
|
if (!endptr) {
|
||||||
log_error("Could not parse histogram value.");
|
log_error("Could not parse histogram value.");
|
||||||
return 0;
|
goto bad;
|
||||||
}
|
}
|
||||||
c = endptr; /* Advance to colon, or end. */
|
c = endptr; /* Advance to colon, or end. */
|
||||||
|
|
||||||
if (*c == ':')
|
if (*c == ':')
|
||||||
c++;
|
c++;
|
||||||
else if (*c & (*c != '\n')) {
|
else if (*c & (*c != '\n'))
|
||||||
/* Expected ':', '\n', or NULL. */
|
/* Expected ':', '\n', or NULL. */
|
||||||
stack;
|
|
||||||
goto badchar;
|
goto badchar;
|
||||||
}
|
|
||||||
|
|
||||||
if (*c == ':')
|
if (*c == ':')
|
||||||
c++;
|
c++;
|
||||||
@ -763,7 +759,8 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
cur.count = this_val;
|
cur.count = this_val;
|
||||||
sum += this_val;
|
sum += this_val;
|
||||||
|
|
||||||
dm_pool_grow_object(mem, &cur, sizeof(cur));
|
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
||||||
|
goto_bad;
|
||||||
|
|
||||||
bin++;
|
bin++;
|
||||||
}
|
}
|
||||||
@ -778,6 +775,8 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
|
|
||||||
badchar:
|
badchar:
|
||||||
log_error("Invalid character in histogram data: '%c' (0x%x)", *c, *c);
|
log_error("Invalid character in histogram data: '%c' (0x%x)", *c, *c);
|
||||||
|
bad:
|
||||||
|
dm_pool_abandon_object(mem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user