diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-22 18:25:00 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-22 22:20:31 -0400 |
commit | 45656a484df853d71670eb4bd1576cfc21fcc8a3 (patch) | |
tree | 33ca563d8687e9888189bffe4c0f75eb25861f32 | |
parent | 3c36d85db7c689cc20f480492d6ee4f43d27cbf8 (diff) | |
download | stasis-45656a484df853d71670eb4bd1576cfc21fcc8a3.tar.gz |
Fix bad realloc
* Tests temporary pointer instead of blindly replacing the original
-rw-r--r-- | src/utils.c | 10 |
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); } } |