diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-26 02:15:59 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-26 02:15:59 -0400 |
commit | 37ec63ece45c7f27f576e1fb5911b55630125d03 (patch) | |
tree | 843d82c165c784997bedf2ad36f078f932b1643d /lib/manifest.c | |
parent | d0925dcc2e34d6f9a8c554ca97c4d75784e6f69d (diff) | |
download | spmc-37ec63ece45c7f27f576e1fb5911b55630125d03.tar.gz |
Fix segfault caused by freeing records for no reason:
* split() returns the input string when no delimiters are found
Diffstat (limited to 'lib/manifest.c')
-rw-r--r-- | lib/manifest.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/manifest.c b/lib/manifest.c index 08aafbf..2d306e7 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -474,9 +474,10 @@ Manifest *manifest_read(char *file_or_url) { info->records = total_records; while (fgets(dptr, BUFSIZ, fp) != NULL) { dptr = strip(dptr); - char *garbage; + char *garbage = NULL; char **parts = split(dptr, separator); char *_origin = NULL; + if (file_or_url != NULL) { _origin = strdup(file_or_url); } @@ -499,7 +500,6 @@ Manifest *manifest_read(char *file_or_url) { info->packages[i]->requirements = NULL; if (strncmp(parts[6], SPM_MANIFEST_NODATA, strlen(SPM_MANIFEST_NODATA)) != 0) { info->packages[i]->requirements = split(parts[6], ","); - } if (strncmp(parts[7], SPM_MANIFEST_NODATA, strlen(SPM_MANIFEST_NODATA)) != 0) { memset(info->packages[i]->checksum_sha256, '\0', SHA256_DIGEST_STRING_LENGTH); @@ -527,14 +527,14 @@ Manifest *manifest_read(char *file_or_url) { */ ManifestPackage *manifest_search(const Manifest *info, const char *_package) { ManifestPackage *match = NULL; - char package[PATH_MAX]; - - memset(package, '\0', PATH_MAX); - strncpy(package, _package, PATH_MAX); + char *package = strdup(_package); if ((match = find_by_strspec(info, package)) != NULL) { + free(package); return match; } + + free(package); return NULL; } |