Merge pull request #27770 from mrc0mmand/more-nallocfuzz-shenanigans
A couple of fixes for potential issues during OOM situations
This commit is contained in:
@@ -268,6 +268,10 @@ int introspect_finish(struct introspect *i, char **ret) {
|
||||
return r;
|
||||
|
||||
i->f = safe_fclose(i->f);
|
||||
|
||||
if (!i->introspection)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(i->introspection);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -824,6 +824,7 @@ int bus_match_parse(
|
||||
|
||||
char *bus_match_to_string(struct bus_match_component *components, size_t n_components) {
|
||||
_cleanup_free_ char *buffer = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
size_t size = 0;
|
||||
int r;
|
||||
|
||||
@@ -832,7 +833,7 @@ char *bus_match_to_string(struct bus_match_component *components, size_t n_compo
|
||||
|
||||
assert(components);
|
||||
|
||||
FILE *f = open_memstream_unlocked(&buffer, &size);
|
||||
f = open_memstream_unlocked(&buffer, &size);
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
@@ -855,9 +856,11 @@ char *bus_match_to_string(struct bus_match_component *components, size_t n_compo
|
||||
}
|
||||
|
||||
r = fflush_and_check(f);
|
||||
safe_fclose(f);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
|
||||
f = safe_fclose(f);
|
||||
|
||||
return TAKE_PTR(buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,9 @@ static int finish_item(
|
||||
char *payload, size_t payload_size) {
|
||||
|
||||
_cleanup_free_ CatalogItem *i = NULL;
|
||||
_cleanup_free_ char *prev = NULL, *combined = NULL;
|
||||
_cleanup_free_ char *combined = NULL;
|
||||
char *prev;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
assert(payload);
|
||||
@@ -168,19 +170,24 @@ static int finish_item(
|
||||
if (!combined)
|
||||
return log_oom();
|
||||
|
||||
if (ordered_hashmap_update(h, i, combined) < 0)
|
||||
return log_oom();
|
||||
combined = NULL;
|
||||
r = ordered_hashmap_update(h, i, combined);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
TAKE_PTR(combined);
|
||||
free(prev);
|
||||
} else {
|
||||
/* A new item */
|
||||
combined = memdup(payload, payload_size + 1);
|
||||
if (!combined)
|
||||
return log_oom();
|
||||
|
||||
if (ordered_hashmap_put(h, i, combined) < 0)
|
||||
return log_oom();
|
||||
i = NULL;
|
||||
combined = NULL;
|
||||
r = ordered_hashmap_put(h, i, combined);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
TAKE_PTR(i);
|
||||
TAKE_PTR(combined);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user