From 12b9e4408d7e1edd1741d5afdf359bca82d3f75e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 25 Nov 2020 11:38:01 +0100 Subject: [PATCH] winexe: Fix a possible null pointer derference Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- examples/winexe/winexe.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/winexe/winexe.c b/examples/winexe/winexe.c index 95386211c0a..529858ccbb8 100644 --- a/examples/winexe/winexe.c +++ b/examples/winexe/winexe.c @@ -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; } -- 2.47.3