From 321ee914a4b5232c2ff451352e2f5b5d0bf9a96c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 21 Jun 2024 10:48:01 +0200 Subject: [PATCH] s3:libsmb: Check if we have a valid file descriptor "Error: REVERSE_NEGATIVE (CWE-191): samba-4.20.0rc2/source3/libsmb/pylibsmb.c:215: negative_sink_in_call: Passing ""t->shutdown_pipe[1]"" to a parameter that cannot be negative. samba-4.20.0rc2/source3/libsmb/pylibsmb.c:230: check_after_sink: You might be using variable ""t->shutdown_pipe[1]"" before verifying that it is >= 0. 228| t->shutdown_pipe[0] = -1; 229| } 230|-> if (t->shutdown_pipe[1] != -1) { 231| close(t->shutdown_pipe[1]); 232| t->shutdown_pipe[1] = -1;" Signed-off-by: Andreas Schneider Reviewed-by: Martin Schwenke --- source3/libsmb/pylibsmb.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index 091cfee76bd..8dbef93834b 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -208,12 +208,14 @@ static int py_cli_thread_destructor(struct py_cli_thread *t) ssize_t written; int ret; - do { - /* - * This will wake the poll thread from the poll(2) - */ - written = write(t->shutdown_pipe[1], &c, 1); - } while ((written == -1) && (errno == EINTR)); + if (t->shutdown_pipe[1] != -1) { + do { + /* + * This will wake the poll thread from the poll(2) + */ + written = write(t->shutdown_pipe[1], &c, 1); + } while ((written == -1) && (errno == EINTR)); + } /* * Allow the poll thread to do its own cleanup under the GIL -- 2.47.3