]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/tcbfuncs.c: rmdir_leading(): Constify input
authorAlejandro Colomar <alx@kernel.org>
Sat, 16 Nov 2024 17:16:40 +0000 (18:16 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sun, 7 Dec 2025 04:38:06 +0000 (22:38 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/tcbfuncs.c

index 8b72acc33479d16440e31980d2522369d0dac8c9..499a1a9fc49857e385adaaea5caf36010952eada 100644 (file)
@@ -254,17 +254,23 @@ static shadowtcb_status unlink_suffs (const char *user)
 }
 
 /* path should be a relative existing tcb directory */
-static shadowtcb_status rmdir_leading (char *path)
+static shadowtcb_status
+rmdir_leading(const char *relpath)
 {
-       char *ind, *dir;
+       char  *ind, *dir, *path;
        shadowtcb_status ret = SHADOWTCB_SUCCESS;
+
+       path = strdup(relpath);
+       if (path == NULL)
+               goto oom;
+
+
        while ((ind = strrchr (path, '/'))) {
                stpcpy(ind, "");
                dir = aprintf(TCB_DIR "/%s", path);
-               if (dir == NULL) {
-                       OUT_OF_MEMORY;
-                       return SHADOWTCB_FAILURE;
-               }
+               if (dir == NULL)
+                       goto free_path;
+
                if (rmdir (dir) != 0) {
                        if (errno != ENOTEMPTY) {
                                fprintf (shadow_logfd,
@@ -277,7 +283,15 @@ static shadowtcb_status rmdir_leading (char *path)
                }
                free (dir);
        }
+
+       free(path);
        return ret;
+
+free_path:
+       free(path);
+oom:
+       OUT_OF_MEMORY;
+       return SHADOWTCB_FAILURE;
 }
 
 static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid)