File U_07-Use-rmdir_recursive.patch of Package slurm.31080
From: Tim Wickberg <tim@schedmd.com>
Date: Wed Oct 11 12:45:25 2023 -0600
Subject: [PATCH 7/19]Use rmdir_recursive().
Patch-mainline: Upstream
Git-repo: https://github.com/SchedMD/slurm
Git-commit: 2370daf819d886a376e5c75f07accac584d544ca
References: bsc#1216207
Signed-off-by: Egbert Eich <eich@suse.de>
Instead of vulnerable local version.
Co-authored-by: Alejandro Sanchez <alex@schedmd.com>
---
src/plugins/mpi/cray_shasta/mpi_cray_shasta.c | 59 +--------------------------
1 file changed, 2 insertions(+), 57 deletions(-)
diff --git a/src/plugins/mpi/cray_shasta/mpi_cray_shasta.c b/src/plugins/mpi/cray_shasta/mpi_cray_shasta.c
index 95b8b58d31..14838013ea 100644
--- a/src/plugins/mpi/cray_shasta/mpi_cray_shasta.c
+++ b/src/plugins/mpi/cray_shasta/mpi_cray_shasta.c
@@ -45,6 +45,7 @@
#include "src/common/slurm_xlator.h"
#include "src/common/env.h"
+#include "src/common/fd.h"
#include "src/common/slurm_mpi.h"
#include "src/slurmd/slurmstepd/slurmstepd_job.h"
@@ -175,62 +176,6 @@ static void _set_pmi_port(char ***env)
env_array_overwrite_fmt(env, "PMI_CONTROL_PORT", "%lu", pmi_port);
}
-/*
- * Determine whether the given path is a directory
- */
-static int _is_dir(char *path)
-{
- struct stat stat_buf;
-
- if (stat(path, &stat_buf)) {
- error("%s: Cannot stat %s: %m", plugin_type, path);
- return 1;
- } else if (!S_ISDIR(stat_buf.st_mode)) {
- return 0;
- }
- return 1;
-}
-
-/*
- * Recursively remove a directory
- */
-static int _rmdir_recursive(char *path)
-{
- char nested_path[PATH_MAX];
- DIR *dp;
- struct dirent *ent;
-
- if (!(dp = opendir(path))) {
- error("%s: Can't open directory %s: %m", plugin_type, path);
- return SLURM_ERROR;
- }
-
- while ((ent = readdir(dp))) {
- if (!xstrcmp(ent->d_name, ".") ||
- !xstrcmp(ent->d_name, "..")) {
- /* skip special dir's */
- continue;
- }
- snprintf(nested_path, sizeof(nested_path), "%s/%s", path,
- ent->d_name);
- if (_is_dir(nested_path)) {
- _rmdir_recursive(nested_path);
- } else {
- debug("%s: Removed file %s", plugin_type, nested_path);
- unlink(nested_path);
- }
- }
- closedir(dp);
-
- if (rmdir(path) == -1) {
- error("%s: Can't remove directory %s: %m",
- plugin_type, path);
- return SLURM_ERROR;
- }
-
- debug("%s: Removed directory %s", plugin_type, path);
- return SLURM_SUCCESS;
-}
extern int p_mpi_hook_slurmstepd_prefork(
const stepd_step_rec_t *job, char ***env)
@@ -285,7 +230,7 @@ extern int fini(void)
{
// Remove application spool directory
if (appdir)
- _rmdir_recursive(appdir);
+ rmdir_recursive(appdir, true);
// Free allocated storage
xfree(appdir);