]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: Check if we have a valid file descriptor
authorAndreas Schneider <asn@samba.org>
Fri, 21 Jun 2024 08:48:01 +0000 (10:48 +0200)
committerMartin Schwenke <martins@samba.org>
Sun, 30 Jun 2024 23:20:34 +0000 (23:20 +0000)
"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 <asn@samba.org>
Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
source3/libsmb/pylibsmb.c

index 091cfee76bd64d072e7c9dff40e008633d86d88d..8dbef93834b15226538862fdb4b7b9ddc6779be5 100644 (file)
@@ -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