diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-18 09:12:13 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-18 09:13:49 -0500 |
commit | 6292c699248d3dfa6271ae0961e63436615653f2 (patch) | |
tree | c456bacd51414480179c60e520867c8ff9cc1836 /src/fs.c | |
parent | 1c2cdc4d8e28ce1b4c0d1ba75686f05fd5dd772d (diff) | |
download | spmc-6292c699248d3dfa6271ae0961e63436615653f2.tar.gz |
Rework dependency scanning:
* Stop resolving dependencies during manifest creation
* Resolve dependencies by path
* Die on failure to resolve
* Fixed an off-by-one error in manifest_read
* Add CLI argument -M|--override-manifest to disable default manifest(s)
* Clean up expandpath() a bit
Diffstat (limited to 'src/fs.c')
-rw-r--r-- | src/fs.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -182,6 +182,9 @@ void fstree_free(FSTree *fsdata) { * @return success=expanded path or original path, failure=NULL */ char *expandpath(const char *_path) { + if (_path == NULL) { + return NULL; + } const char *homes[] = { "HOME", "USERPROFILE", @@ -196,7 +199,7 @@ char *expandpath(const char *_path) { memset(ptmp, '\0', sizeof(tmp)); memset(result, '\0', sizeof(result)); - strncpy(ptmp, _path, strlen(_path)); + strncpy(ptmp, _path, PATH_MAX - 1); // Check whether there's a reason to continue processing the string if (*ptmp != '~') { @@ -210,7 +213,7 @@ char *expandpath(const char *_path) { for (size_t i = 0; i < sizeof(homes); i++) { char *tmphome; if ((tmphome = getenv(homes[i])) != NULL) { - strncpy(home, tmphome, strlen(tmphome)); + strncpy(home, tmphome, PATH_MAX - 1); break; } } @@ -227,9 +230,10 @@ char *expandpath(const char *_path) { } // Construct the new path - strncat(result, home, strlen(home)); + strncat(result, home, PATH_MAX - 1); if (sep) { - sprintf(result, "%c%s", DIRSEP, ptmp); + strncat(result, DIRSEPS, PATH_MAX - 1); + strncat(result, ptmp, PATH_MAX - 1); } return strdup(result); |