]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb:clilist fix tautological-compare
authorGary Lockyer <gary@catalyst.net.nz>
Tue, 14 Apr 2026 22:58:15 +0000 (10:58 +1200)
committerStefan Metzmacher <metze@samba.org>
Thu, 28 May 2026 17:39:48 +0000 (17:39 +0000)
The wrapping of pointer arithmetic is undefined behaviour. Clang from version 20
onwards will treat an overflow check of the following form:
   ptr + offset < ptr
as always evaluating to false.

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

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/libsmb/clilist.c

index 9ec3e3240f472c2f240223a1e5d65fb30335e816..f8d23c634cc4c07fc1cd611cc85e7d7fa25102dc 100644 (file)
@@ -22,6 +22,7 @@
 #include "source3/libsmb/proto.h"
 #include "source3/libsmb/cli_smb2_fnum.h"
 #include "../lib/util/tevent_ntstatus.h"
+#include "../lib/util/overflow.h"
 #include "async_smb.h"
 #include "trans2.h"
 #include "../libcli/smb/smbXcli_base.h"
@@ -97,8 +98,8 @@ static size_t calc_next_entry_offset(const char *base, const char *pdata_end)
        size_t next_entry_offset = (size_t)IVAL(base,0);
 
        if (next_entry_offset == 0 ||
-                       base + next_entry_offset < base ||
-                       base + next_entry_offset > pdata_end) {
+           offset_outside_range(base, pdata_end, next_entry_offset))
+       {
                next_entry_offset = pdata_end - base;
        }
        return next_entry_offset;
@@ -283,7 +284,7 @@ static size_t interpret_long_filename(TALLOC_CTX *ctx,
                                return pdata_end - base;
                        }
                        p += 24; /* short name? */
-                       if (p + namelen < p || p + namelen > pdata_end) {
+                       if (offset_outside_range(p, pdata_end, namelen)) {
                                return pdata_end - base;
                        }
                        ret = pull_string_talloc(ctx,