From: Alejandro Colomar Date: Sat, 16 Nov 2024 17:16:40 +0000 (+0100) Subject: lib/tcbfuncs.c: rmdir_leading(): Constify input X-Git-Tag: 4.19.0-rc1~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4cf430b30936109c38983fcdc37523f021cb6002;p=thirdparty%2Fshadow.git lib/tcbfuncs.c: rmdir_leading(): Constify input Signed-off-by: Alejandro Colomar --- diff --git a/lib/tcbfuncs.c b/lib/tcbfuncs.c index 8b72acc3..499a1a9f 100644 --- a/lib/tcbfuncs.c +++ b/lib/tcbfuncs.c @@ -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)