]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samr: Fix CID 1035506: close slave fd (REASOURCE_LEAK)
authorShachar Sharon <ssharon@redhat.com>
Tue, 19 Aug 2025 08:34:13 +0000 (11:34 +0300)
committerAnoop C S <anoopcs@samba.org>
Thu, 11 Sep 2025 13:29:37 +0000 (13:29 +0000)
In the case of (unlikely) failure of dup2 on one of the standard file
descriptors, close 'slave' fd upon return.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Thu Sep 11 13:29:37 UTC 2025 on atb-devel-224

source3/rpc_server/samr/srv_samr_chgpasswd.c

index 6c0c0da0cfc355796477fe7a8464cfbc27933660..000f6c2b87dc07869da08a6bbd4cde7744350ef9 100644 (file)
@@ -201,18 +201,24 @@ static int dochild(int master, const char *slavedev, const struct passwd *pass,
 
        /* Make slave stdin/out/err of child. */
 
-       if (dup2(slave, STDIN_FILENO) != STDIN_FILENO)
+       if ((slave != STDIN_FILENO) &&
+           (dup2(slave, STDIN_FILENO) != STDIN_FILENO))
        {
+               close(slave);
                DEBUG(3, ("Could not re-direct stdin\n"));
                return (False);
        }
-       if (dup2(slave, STDOUT_FILENO) != STDOUT_FILENO)
+       if ((slave != STDOUT_FILENO) &&
+           (dup2(slave, STDOUT_FILENO) != STDOUT_FILENO))
        {
+               close(slave);
                DEBUG(3, ("Could not re-direct stdout\n"));
                return (False);
        }
-       if (dup2(slave, STDERR_FILENO) != STDERR_FILENO)
+       if ((slave != STDERR_FILENO) &&
+           (dup2(slave, STDERR_FILENO) != STDERR_FILENO))
        {
+               close(slave);
                DEBUG(3, ("Could not re-direct stderr\n"));
                return (False);
        }