winexe: Fix a possible null pointer derference
authorAndreas Schneider <asn@samba.org>
Wed, 25 Nov 2020 10:38:01 +0000 (11:38 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 26 Nov 2020 09:44:42 +0000 (09:44 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
examples/winexe/winexe.c

index 95386211c0a62fd02c400ca3c63cfec473524392..529858ccbb8e0d486bafcfb3a4e32898821a6500 100644 (file)
@@ -347,7 +347,7 @@ static NTSTATUS winexe_svc_upload(
        int flags)
 {
        struct cli_state *cli;
-       uint16_t fnum;
+       uint16_t fnum = 0xffff;
        NTSTATUS status;
        const DATA_BLOB *binary = NULL;
 
@@ -389,7 +389,7 @@ static NTSTATUS winexe_svc_upload(
        }
 
        if (binary == NULL) {
-               //TODO
+               goto done;
        }
 
        status = cli_ntcreate(
@@ -420,16 +420,20 @@ static NTSTATUS winexe_svc_upload(
                NULL);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("Could not write file: %s\n", nt_errstr(status));
-               goto close_done;
+               goto done;
        }
 
-close_done:
-       status = cli_close(cli, fnum);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_WARNING("Close(%"PRIu16") failed for %s: %s\n", fnum,
-                           service_filename, nt_errstr(status));
-       }
 done:
+       if (fnum != 0xffff) {
+               status = cli_close(cli, fnum);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_WARNING("Close(%"PRIu16") failed for %s: %s\n",
+                                   fnum,
+                                   service_filename,
+                                   nt_errstr(status));
+               }
+       }
+
        TALLOC_FREE(cli);
        return status;
 }