]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb_xattr: ace_compare() uses NUMERIC_CMP()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 4 Apr 2024 01:33:47 +0000 (14:33 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 10 Apr 2024 23:58:12 +0000 (23:58 +0000)
the access_mask is the easiest to overflow with subtraction -- other
fields are 8 or 16 bit.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Apr 10 23:58:12 UTC 2024 on atb-devel-224

source3/libsmb/libsmb_xattr.c

index dcb2f9e74a77af3da80efb481cdacd5c7f5b4869..a90234193765c81e134f46d69e95a20abe7c1cb2 100644 (file)
@@ -121,7 +121,13 @@ ace_compare(struct security_ace *ace1,
          */
 
        if (ace1->type != ace2->type) {
-               return ace2->type - ace1->type;
+               /*
+                * ace2 and ace1 are reversed here, so that
+                * ACCESS_DENIED_ACE_TYPE (1) sorts before
+                * ACCESS_ALLOWED_ACE_TYPE (0), which is the order you
+                * usually want.
+                */
+               return NUMERIC_CMP(ace2->type, ace1->type);
         }
 
        if (dom_sid_compare(&ace1->trustee, &ace2->trustee)) {
@@ -129,15 +135,15 @@ ace_compare(struct security_ace *ace1,
         }
 
        if (ace1->flags != ace2->flags) {
-               return ace1->flags - ace2->flags;
+               return NUMERIC_CMP(ace1->flags, ace2->flags);
         }
 
        if (ace1->access_mask != ace2->access_mask) {
-               return ace1->access_mask - ace2->access_mask;
+               return NUMERIC_CMP(ace1->access_mask, ace2->access_mask);
         }
 
        if (ace1->size != ace2->size) {
-               return ace1->size - ace2->size;
+               return NUMERIC_CMP(ace1->size, ace2->size);
         }
 
        return memcmp(ace1, ace2, sizeof(struct security_ace));