aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-03-22 18:25:00 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-03-22 22:20:31 -0400
commit45656a484df853d71670eb4bd1576cfc21fcc8a3 (patch)
tree33ca563d8687e9888189bffe4c0f75eb25861f32 /src/utils.c
parent3c36d85db7c689cc20f480492d6ee4f43d27cbf8 (diff)
downloadstasis-45656a484df853d71670eb4bd1576cfc21fcc8a3.tar.gz
Fix bad realloc
* Tests temporary pointer instead of blindly replacing the original
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index 51c11e8..da3833c 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -628,7 +628,15 @@ int fix_tox_conf(const char *filename, char **result) {
if (data) {
if (!strcmp(data->key, "commands") && (startswith(data->value, "pytest") && !strstr(data->value, "{posargs}"))) {
strip(data->value);
- data->value = realloc(data->value, strlen(data->value) + strlen(with_posargs) + 1);
+ char *tmp;
+ tmp = realloc(data->value, strlen(data->value) + strlen(with_posargs) + 1);
+ if (!tmp) {
+ SYSERROR("failed to increase data->value size to +%zu bytes", strlen(data->value) + strlen(with_posargs) + 1);
+ guard_free(result);
+ return -1;
+ } else if (tmp != data->value) {
+ data->value = tmp;
+ }
strcat(data->value, with_posargs);
}
}