s3:utils: Do not leak memory in new_user()
authorAndreas Schneider <asn@samba.org>
Thu, 9 Aug 2018 14:30:03 +0000 (16:30 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 10 Aug 2018 23:49:16 +0000 (01:49 +0200)
Found by covscan.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13567

Pair-Programmed-With: Justin Stephenson <jstephen@redhat.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/pdbedit.c

index a353bae7c4eb31b108a323b07fed2e6e57dd63d4..5c947e2fbde5ba3d62528daa8097dce8ecf7fae0 100644 (file)
@@ -750,7 +750,7 @@ static int new_user(const char *username, const char *fullname,
        NTSTATUS status;
        struct dom_sid u_sid;
        int flags;
-       int ret;
+       int ret = -1;
 
        tosctx = talloc_tos();
        if (!tosctx) {
@@ -766,10 +766,14 @@ static int new_user(const char *username, const char *fullname,
        }
 
        pwd1 = get_pass( "new password:", stdin_get);
+       if (pwd1 == NULL) {
+               fprintf(stderr, "Failed to read passwords.\n");
+               goto done;
+       }
        pwd2 = get_pass( "retype new password:", stdin_get);
-       if (!pwd1 || !pwd2) {
+       if (pwd2 == NULL) {
                fprintf(stderr, "Failed to read passwords.\n");
-               return -1;
+               goto done;
        }
        ret = strcmp(pwd1, pwd2);
        if (ret != 0) {