diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-08-22 11:17:27 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-08-22 09:18:04 -0700 |
| commit | 149c9e200c18316432a99a9b5edfa0d0b4d50bc5 (patch) | |
| tree | c088f2bd35ded0f0068a44b5cc4b008a893a9e63 /builtin/upload-archive.c | |
| parent | ff0935b96e414ff7115f281308c33fb93e4e26ce (diff) | |
| download | git-149c9e200c18316432a99a9b5edfa0d0b4d50bc5.tar.gz | |
builtin/upload-archive: fix leaking args passed to `write_archive()`
In git-upload-archive(1), we pass an array of arguments to
`write_archive()` to tell it what exactly to do. We don't ever clear the
vector though, causing a memory leak. Furthermore though, the call to
`write_archive()` may cause contents of the array to be modified, which
would cause us to leak memory to allocated strings held by it.
Fix the issue by having `write_archive()` create a shallow copy of
`argv` before parsing the arguments. Like this, we won't modify the
caller's array and can easily `strvec_clear()` it to plug these memory
leaks.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/upload-archive.c')
| -rw-r--r-- | builtin/upload-archive.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 1b09e5e1aa..313a8dfa81 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -22,6 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { struct strvec sent_argv = STRVEC_INIT; const char *arg_cmd = "argument "; + int ret; if (argc != 2 || !strcmp(argv[1], "-h")) usage(upload_archive_usage); @@ -46,8 +47,11 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) } /* parse all options sent by the client */ - return write_archive(sent_argv.nr, sent_argv.v, prefix, - the_repository, NULL, 1); + ret = write_archive(sent_argv.nr, sent_argv.v, prefix, + the_repository, NULL, 1); + + strvec_clear(&sent_argv); + return ret; } __attribute__((format (printf, 1, 2))) |
