diff options
| -rw-r--r-- | src/docker.c | 5 | ||||
| -rw-r--r-- | src/environment.c | 4 | ||||
| -rw-r--r-- | src/recipe.c | 2 | ||||
| -rw-r--r-- | src/stasis_indexer.c | 4 | ||||
| -rw-r--r-- | src/utils.c | 13 | 
5 files changed, 17 insertions, 11 deletions
| diff --git a/src/docker.c b/src/docker.c index da7c1ce..2d5e2cc 100644 --- a/src/docker.c +++ b/src/docker.c @@ -44,8 +44,9 @@ int docker_script(const char *image, char *data, unsigned flags) {      do {          memset(buffer, 0, sizeof(buffer)); -        fgets(buffer, sizeof(buffer) - 1, infile); -        fputs(buffer, outfile); +        if (fgets(buffer, sizeof(buffer) - 1, infile) != NULL) { +            fputs(buffer, outfile); +        }      } while (!feof(infile));      fclose(infile); diff --git a/src/environment.c b/src/environment.c index 924fbf8..580062c 100644 --- a/src/environment.c +++ b/src/environment.c @@ -305,7 +305,7 @@ char *runtime_expand_var(RuntimeEnv *env, char *input) {          // Handle literal statement "$$var"          // Value becomes "$var" (unexpanded)          if (strncmp(&input[i], delim_literal, strlen(delim_literal)) == 0) { -            strncat(expanded, &delim, 1); +            strncat(expanded, &delim, 2);              i += strlen(delim_literal);              // Ignore opening brace              if (input[i] == '{') { @@ -349,7 +349,7 @@ char *runtime_expand_var(RuntimeEnv *env, char *input) {                  continue;              }              // Append expanded environment variable to output -            strncat(expanded, tmp, strlen(tmp)); +            strncat(expanded, tmp, STASIS_BUFSIZ - 1);              if (env) {                  guard_free(tmp);              } diff --git a/src/recipe.c b/src/recipe.c index e51fde6..833908c 100644 --- a/src/recipe.c +++ b/src/recipe.c @@ -16,7 +16,7 @@ int recipe_clone(char *recipe_dir, char *url, char *gitref, char **result) {              return -1;          }      } -    strncpy(*result, destdir, PATH_MAX - 1); +    strncpy(*result, destdir, PATH_MAX);      if (!access(destdir, F_OK)) {          if (!strcmp(destdir, "/")) { diff --git a/src/stasis_indexer.c b/src/stasis_indexer.c index ef6375b..8ee575e 100644 --- a/src/stasis_indexer.c +++ b/src/stasis_indexer.c @@ -381,7 +381,9 @@ int indexer_make_website(struct Delivery *ctx) {                  char link_dest[PATH_MAX] = {0};                  strcpy(link_from, "README.html");                  sprintf(link_dest, "%s/%s", root, "index.html"); -                symlink(link_from, link_dest); +                if (symlink(link_from, link_dest)) { +                    SYSERROR("Warning: symlink(%s, %s) failed: %s", link_from, link_dest, strerror(errno)); +                }              }          }          guard_strlist_free(&inputs); diff --git a/src/utils.c b/src/utils.c index c0b3733..63c0cb7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -34,7 +34,7 @@ int popd() {  int rmtree(char *_path) {      int status = 0;      char path[PATH_MAX] = {0}; -    strncpy(path, _path, sizeof(path)); +    strncpy(path, _path, sizeof(path) - 1);      DIR *dir;      struct dirent *d_entity; @@ -122,10 +122,10 @@ char *expandpath(const char *_path) {      }      // Construct the new path -    strncat(result, home, PATH_MAX - 1); +    strncat(result, home, sizeof(result) - strlen(home) + 1);      if (sep) { -        strncat(result, DIR_SEP, PATH_MAX - 1); -        strncat(result, ptmp, PATH_MAX - 1); +        strncat(result, DIR_SEP, sizeof(result) - strlen(home) + 1); +        strncat(result, ptmp, sizeof(result) - strlen(home) + 1);      }      return strdup(result); @@ -444,7 +444,10 @@ void msg(unsigned type, char *fmt, ...) {  void debug_shell() {      msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "ENTERING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET); -    system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'"); +    if (system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'") < 0) { +        SYSERROR("unable to spawn debug shell: %s", strerror(errno)); +        exit(errno); +    }      msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "EXITING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET);      exit(255);  } | 
