summaryrefslogtreecommitdiff
path: root/libdm/libdm-stats.c
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-09-07 11:44:53 +0100
committerBryn M. Reeves <bmr@redhat.com>2015-09-07 11:44:53 +0100
commit36b09fd1471ecbae84b22075b46fada2bd8761ee (patch)
treee02ba070362d55c2d3b5fad0377d2caa2f46bf55 /libdm/libdm-stats.c
parenta26523330e8f461b90eca7d2dcea0d0a6866e635 (diff)
downloadlvm2-36b09fd1471ecbae84b22075b46fada2bd8761ee.tar.gz
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.
Diffstat (limited to 'libdm/libdm-stats.c')
-rw-r--r--libdm/libdm-stats.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index 93c77605c..561637051 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -721,22 +721,20 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
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 {
memset(&cur, 0, sizeof(cur));
for (v = _valid_chars; *v; v++)
if (*c == *v)
break;
- if (!*v) {
- stack;
+ if (!*v)
goto badchar;
- }
- if (*c == ',') {
- log_error("Invalid histogram: %s", hist_str);
- return 0;
- } else {
+ if (*c == ',')
+ goto badchar;
+ else {
const char *val_start = c;
char *endptr = NULL;
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);
if (!endptr) {
log_error("Could not parse histogram value.");
- return 0;
+ goto bad;
}
c = endptr; /* Advance to colon, or end. */
if (*c == ':')
c++;
- else if (*c & (*c != '\n')) {
+ else if (*c & (*c != '\n'))
/* Expected ':', '\n', or NULL. */
- stack;
goto badchar;
- }
if (*c == ':')
c++;
@@ -763,7 +759,8 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
cur.count = 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++;
}
@@ -778,6 +775,8 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
badchar:
log_error("Invalid character in histogram data: '%c' (0x%x)", *c, *c);
+bad:
+ dm_pool_abandon_object(mem);
return 0;
}