diff options
Diffstat (limited to 'src/lib/delivery')
| -rw-r--r-- | src/lib/delivery/delivery_build.c | 30 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_docker.c | 6 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_init.c | 29 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_install.c | 48 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_test.c | 15 |
5 files changed, 47 insertions, 81 deletions
diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c index 66f9126..d8674e0 100644 --- a/src/lib/delivery/delivery_build.c +++ b/src/lib/delivery/delivery_build.c @@ -34,15 +34,12 @@ int delivery_build_recipes(struct Delivery *ctx) { const int is_long_tag = num_chars(ctx->tests->test[i]->repository_info_tag, '-') > 1; if (is_long_tag) { const size_t len = strcspn(ctx->tests->test[i]->repository_info_tag, "-"); - strncpy(tag, ctx->tests->test[i]->repository_info_tag, len); - tag[len] = '\0'; + safe_strncpy(tag, ctx->tests->test[i]->repository_info_tag, len); } else { - strncpy(tag, ctx->tests->test[i]->repository_info_tag, sizeof(tag) - 1); - tag[sizeof(tag) - 1] = '\0'; + safe_strncpy(tag, ctx->tests->test[i]->repository_info_tag, sizeof(tag)); } } else { - strncpy(tag, ctx->tests->test[i]->version, sizeof(tag) - 1); - tag[sizeof(tag) - 1] = '\0'; + safe_strncpy(tag, ctx->tests->test[i]->version, sizeof(tag)); } //sprintf(recipe_version, "{%% set version = GIT_DESCRIBE_TAG ~ \".dev\" ~ GIT_DESCRIBE_NUMBER ~ \"+\" ~ GIT_DESCRIBE_HASH %%}"); @@ -55,8 +52,7 @@ int delivery_build_recipes(struct Delivery *ctx) { snprintf(recipe_version, sizeof(recipe_version), "{%% set version = \"%s\" %%}", tag); snprintf(recipe_git_url, sizeof(recipe_git_url), " url: %s/archive/refs/tags/{{ version }}.tar.gz", ctx->tests->test[i]->repository); - strncpy(recipe_git_rev, "", sizeof(recipe_git_rev) - 1); - recipe_git_rev[sizeof(recipe_git_rev) - 1] = '\0'; + safe_strncpy(recipe_git_rev, "", sizeof(recipe_git_rev)); snprintf(recipe_buildno, sizeof(recipe_buildno), " number: 0"); unsigned flags = REPLACE_TRUNCATE_AFTER_MATCH; @@ -80,22 +76,20 @@ int delivery_build_recipes(struct Delivery *ctx) { char arch[STASIS_NAME_MAX] = {0}; char platform[STASIS_NAME_MAX] = {0}; - strncpy(platform, ctx->system.platform[DELIVERY_PLATFORM], sizeof(platform) - 1); + safe_strncpy(platform, ctx->system.platform[DELIVERY_PLATFORM], sizeof(platform)); if (strstr(platform, "Darwin")) { memset(platform, 0, sizeof(platform)); - strncpy(platform, "osx", sizeof(platform) - 1); + safe_strncpy(platform, "osx", sizeof(platform)); } - platform[sizeof(platform) - 1] = '\0'; tolower_s(platform); if (strstr(ctx->system.arch, "arm64")) { - strncpy(arch, "arm64", sizeof(arch) - 1); + safe_strncpy(arch, "arm64", sizeof(arch)); } else if (strstr(ctx->system.arch, "64")) { - strncpy(arch, "64", sizeof(arch) - 1); + safe_strncpy(arch, "64", sizeof(arch)); } else { - strncat(arch, "32", sizeof(arch) - strlen(arch) - 1); // blind guess + safe_strncat(arch, "32", sizeof(arch)); // blind guess } - arch[sizeof(arch) - 1] = '\0'; tolower_s(arch); snprintf(command, sizeof(command), "mambabuild --python=%s -m ../.ci_support/%s_%s_.yaml .", @@ -393,8 +387,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { for (size_t p = 0; p < strlist_count(ctx->conda.pip_packages_defer); p++) { char name[100] = {0}; char *fullspec = strlist_item(ctx->conda.pip_packages_defer, p); - strncpy(name, fullspec, sizeof(name) - 1); - name[sizeof(name) - 1] = '\0'; + safe_strncpy(name, fullspec, sizeof(name)); remove_extras(name); char *spec = find_version_spec(name); if (spec) { @@ -444,8 +437,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { COE_CHECK_ABORT(true, "Unreproducible delivery"); } - strncpy(dname, ctx->tests->test[i]->name, sizeof(dname) - 1); - dname[sizeof(dname) - 1] = '\0'; + safe_strncpy(dname, ctx->tests->test[i]->name, sizeof(dname)); tolower_s(dname); snprintf(outdir, sizeof(outdir), "%s/%s", ctx->storage.wheel_artifact_dir, dname); if (mkdirs(outdir, 0755)) { diff --git a/src/lib/delivery/delivery_docker.c b/src/lib/delivery/delivery_docker.c index 79e9729..9b2e1f7 100644 --- a/src/lib/delivery/delivery_docker.c +++ b/src/lib/delivery/delivery_docker.c @@ -44,8 +44,7 @@ int delivery_docker(struct Delivery *ctx) { // Append image tags to command for (size_t i = 0; i < total_tags; i++) { char *tag_orig = strlist_item(ctx->deploy.docker.tags, i); - strncpy(tag, tag_orig, sizeof(tag) - 1); - tag[sizeof(tag) - 1] = '\0'; + safe_strncpy(tag, tag_orig, sizeof(tag)); docker_sanitize_tag(tag); snprintf(args + strlen(args), sizeof(args) - strlen(args), " -t \"%s\" ", tag); } @@ -103,8 +102,7 @@ int delivery_docker(struct Delivery *ctx) { // Test the image // All tags point back to the same image so test the first one we see // regardless of how many are defined - strncpy(tag, strlist_item(ctx->deploy.docker.tags, 0), sizeof(tag) - 1); - tag[sizeof(tag) - 1] = '\0'; + safe_strncpy(tag, strlist_item(ctx->deploy.docker.tags, 0), sizeof(tag)); docker_sanitize_tag(tag); msg(STASIS_MSG_L2, "Executing image test script for %s\n", tag); diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index 5bc326d..7cfb9af 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -217,36 +217,27 @@ int delivery_init_platform(struct Delivery *ctx) { } if (!strcmp(ctx->system.arch, "x86_64")) { - strncpy(archsuffix, "64", sizeof(archsuffix) - 1); + safe_strncpy(archsuffix, "64", sizeof(archsuffix)); } else { - strncpy(archsuffix, ctx->system.arch, sizeof(archsuffix) - 1); + safe_strncpy(archsuffix, ctx->system.arch, sizeof(archsuffix)); } - archsuffix[sizeof(archsuffix) - 1] = '\0'; SYSDEBUG("Setting platform"); - strncpy(ctx->system.platform[DELIVERY_PLATFORM], uts.sysname, DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM], uts.sysname, DELIVERY_PLATFORM_MAXLEN); if (!strcmp(ctx->system.platform[DELIVERY_PLATFORM], "Darwin")) { snprintf(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], DELIVERY_PLATFORM_MAXLEN, "osx-%s", archsuffix); - strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "MacOSX", DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; - strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "macos", DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "MacOSX", DELIVERY_PLATFORM_MAXLEN); + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "macos", DELIVERY_PLATFORM_MAXLEN); } else if (!strcmp(ctx->system.platform[DELIVERY_PLATFORM], "Linux")) { snprintf(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], DELIVERY_PLATFORM_MAXLEN, "linux-%s", archsuffix); - strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "Linux", DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; - strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "linux", DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "Linux", DELIVERY_PLATFORM_MAXLEN); + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "linux", DELIVERY_PLATFORM_MAXLEN); } else { // Not explicitly supported systems - strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; - strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; - strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); - ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN); + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN); + safe_strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN); tolower_s(ctx->system.platform[DELIVERY_PLATFORM_RELEASE]); } diff --git a/src/lib/delivery/delivery_install.c b/src/lib/delivery/delivery_install.c index efdb819..bb99014 100644 --- a/src/lib/delivery/delivery_install.c +++ b/src/lib/delivery/delivery_install.c @@ -34,11 +34,9 @@ static char *have_spec_in_config(const struct Delivery *ctx, const char *name) { char *op = find_version_spec(config_spec); char package[255] = {0}; if (op) { - strncpy(package, config_spec, op - config_spec); - package[op - config_spec] = '\0'; + safe_strncpy(package, config_spec, op - config_spec); } else { - strncpy(package, config_spec, sizeof(package) - 1); - package[sizeof(package) - 1] = '\0'; + safe_strncpy(package, config_spec, sizeof(package)); } remove_extras(package); if (strncmp(package, name, strlen(name)) == 0) { @@ -85,11 +83,9 @@ int delivery_overlay_packages_from_env(struct Delivery *ctx, const char *env_nam char spec_name[255] = {0}; char *op = find_version_spec(spec); if (op) { - strncpy(spec_name, spec, op - spec); - spec_name[op - spec] = '\0'; + safe_strncpy(spec_name, spec, op - spec); } else { - strncpy(spec_name, spec, sizeof(spec_name) - 1); - spec_name[sizeof(spec_name) - 1] = '\0'; + safe_strncpy(spec_name, spec, sizeof(spec_name)); } struct Test *test_block = requirement_from_test(ctx, spec_name); @@ -108,11 +104,9 @@ int delivery_overlay_packages_from_env(struct Delivery *ctx, const char *env_nam char *op = find_version_spec(frozen_spec); // we only care about packages with specs here. if something else arrives, ignore it if (op) { - strncpy(frozen_name, frozen_spec, op - frozen_spec); - frozen_name[op - frozen_spec] = '\0'; + safe_strncpy(frozen_name, frozen_spec, op - frozen_spec); } else { - strncpy(frozen_name, frozen_spec, sizeof(frozen_name) - 1); - frozen_name[sizeof(frozen_name) - 1] = '\0'; + safe_strncpy(frozen_name, frozen_spec, sizeof(frozen_name)); } struct Test *test = requirement_from_test(ctx, frozen_name); if (test && strcmp(test->name, frozen_name) == 0) { @@ -307,20 +301,16 @@ int delivery_purge_packages(struct Delivery *ctx, const char *env_name, int use_ case PKG_USE_CONDA: fn = conda_exec; list = ctx->conda.conda_packages_purge; - strncpy(package_manager, "conda", sizeof(package_manager) - 1); - package_manager[sizeof(package_manager) - 1] = '\0'; + safe_strncpy(package_manager, "conda", sizeof(package_manager)); // conda is already configured for "always_yes" - strncpy(subcommand, "remove", sizeof(subcommand) - 1); - subcommand[sizeof(subcommand) - 1] = '\0'; + safe_strncpy(subcommand, "remove", sizeof(subcommand)); break; case PKG_USE_PIP: fn = pip_exec; list = ctx->conda.pip_packages_purge; - strncpy(package_manager, "pip", sizeof(package_manager) - 1); - package_manager[sizeof(package_manager) - 1] = '\0'; + safe_strncpy(package_manager, "pip", sizeof(package_manager)); // avoid user prompt to remove packages - strncpy(subcommand, "uninstall -y", sizeof(subcommand) - 1); - subcommand[sizeof(subcommand) - 1] = '\0'; + safe_strncpy(subcommand, "uninstall -y", sizeof(subcommand)); break; default: SYSERROR("Unknown package manager: %d", use_pkg_manager); @@ -371,7 +361,7 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha } memset(command_base, 0, sizeof(command_base)); - strncat(command_base, "install", sizeof(command_base) - strlen(command_base) - 1); + safe_strncat(command_base, "install", sizeof(command_base)); typedef int (*Runner)(const char *); Runner runner = NULL; @@ -387,15 +377,17 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha } if (INSTALL_PKG_CONDA_DEFERRED & type) { - strncat(command_base, " --use-local", sizeof(command_base) - strlen(command_base) - 1); - command_base[sizeof(command_base) - 1] = '\0'; + //if (ctx->conda.capabilities.missing_use_local) { + // safe_strncat(command_base, " -c local", sizeof(command_base)); + //} else { + safe_strncat(command_base, " --use-local", sizeof(command_base)); + //} } else if (INSTALL_PKG_PIP_DEFERRED & type) { // Don't change the baseline package set unless we're working with a // new build. Release candidates will need to keep packages as stable // as possible between releases. if (!ctx->meta.based_on) { - strncat(command_base, " --upgrade", sizeof(command_base) - strlen(command_base) - 1); - command_base[sizeof(command_base) - 1] = '\0'; + safe_strncat(command_base, " --upgrade", sizeof(command_base)); } snprintf(command_base + strlen(command_base), sizeof(command_base) - strlen(command_base), " --extra-index-url 'file://%s'", ctx->storage.wheel_artifact_dir); } @@ -470,11 +462,9 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha char req[255] = {0}; if (!strcmp(name, info->name)) { - strncpy(req, info->name, sizeof(req) - 1); - req[sizeof(req) - 1] = '\0'; + safe_strncpy(req, info->name, sizeof(req)); } else { - strncpy(req, name, sizeof(req) - 1); - req[sizeof(req) - 1] = '\0'; + safe_strncpy(req, name, sizeof(req)); char *spec = find_version_spec(req); if (spec) { *spec = 0; diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index f59a62e..c1ef1ad 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -199,13 +199,11 @@ void delivery_tests_run(struct Delivery *ctx) { msg(STASIS_MSG_L3, "Queuing task for %s\n", test->name); memset(&proc, 0, sizeof(proc)); - strncpy(cmd, test->script, strlen(test->script) + STASIS_BUFSIZ - 1); - cmd[strlen(test->script) + STASIS_BUFSIZ - 1] = '\0'; + safe_strncpy(cmd, test->script, strlen(test->script) + STASIS_BUFSIZ); char *cmd_rendered = tpl_render(cmd); if (cmd_rendered) { if (strcmp(cmd_rendered, cmd) != 0) { - strncpy(cmd, cmd_rendered, strlen(test->script) + STASIS_BUFSIZ - 1); - cmd[strlen(cmd_rendered) ? strlen(cmd_rendered) - 1 : 0] = 0; + safe_strncpy(cmd, cmd_rendered, strlen(test->script) + STASIS_BUFSIZ); } guard_free(cmd_rendered); } else { @@ -229,8 +227,7 @@ void delivery_tests_run(struct Delivery *ctx) { if (!globals.enable_parallel || !test->parallel) { selected = SERIAL; memset(pool_name, 0, sizeof(pool_name)); - strncpy(pool_name, "serial", sizeof(pool_name) - 1); - pool_name[sizeof(pool_name) - 1] = '\0'; + safe_strncpy(pool_name, "serial", sizeof(pool_name)); } if (asprintf(&runner_cmd, runner_cmd_fmt, cmd) < 0) { @@ -281,14 +278,12 @@ void delivery_tests_run(struct Delivery *ctx) { exit(1); } - strncpy(cmd, test->script_setup, cmd_len - 1); - cmd[cmd_len - 1] = '\0'; + safe_strncpy(cmd, test->script_setup, cmd_len); char *cmd_rendered = tpl_render(cmd); if (cmd_rendered) { if (strcmp(cmd_rendered, cmd) != 0) { - strncpy(cmd, cmd_rendered, cmd_len - 1); - cmd[strlen(cmd_rendered) ? strlen(cmd_rendered) - 1 : 0] = '\0'; + safe_strncpy(cmd, cmd_rendered, cmd_len); } guard_free(cmd_rendered); } else { |
