Skip to content

Commit cb821d6

Browse files
committed
Replace memccpy(3) by snprintf(3)
1 parent d7ca1b6 commit cb821d6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
2+
* Copyright (c) 2020-2025, NVIDIA CORPORATION. All rights reserved.
33
*/
44

5+
#include <stdio.h>
56
#include <string.h>
67

78
#include <slurm/spank.h>
@@ -39,7 +40,8 @@ int pyxis_config_parse(struct plugin_config *config, int ac, char **av)
3940
for (int i = 0; i < ac; ++i) {
4041
if (strncmp("runtime_path=", av[i], 13) == 0) {
4142
optarg = av[i] + 13;
42-
if (memccpy(config->runtime_path, optarg, '\0', sizeof(config->runtime_path)) == NULL) {
43+
ret = snprintf(config->runtime_path, sizeof(config->runtime_path), "%s", optarg);
44+
if (ret < 0 || ret >= sizeof(config->runtime_path)) {
4345
slurm_error("pyxis: runtime_path: path too long: %s", optarg);
4446
return (-1);
4547
}

pyxis_slurmstepd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,8 @@ static int enroot_create_start_config(char (*path)[PATH_MAX])
820820
}
821821
}
822822

823-
if (memccpy(*path, template, '\0', sizeof(*path)) == NULL)
823+
ret = snprintf(*path, sizeof(*path), "%s", template);
824+
if (ret < 0 || ret >= sizeof(*path))
824825
goto fail;
825826

826827
rv = 0;
@@ -1346,7 +1347,8 @@ static int enroot_container_export(void)
13461347
char path[PATH_MAX];
13471348

13481349
if (context.container.save_path[0] == '/') {
1349-
if (memccpy(path, context.container.save_path, '\0', sizeof(path)) == NULL)
1350+
ret = snprintf(path, sizeof(path), "%s", context.container.save_path);
1351+
if (ret < 0 || ret >= sizeof(path))
13501352
return (-1);
13511353
} else {
13521354
if (context.job.cwd[0] == '\0') {

0 commit comments

Comments
 (0)