]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
fuzzing: fuzz_sddl_parse forgives bad utf-8
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 22 Sep 2023 03:19:32 +0000 (15:19 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 26 Sep 2023 23:45:36 +0000 (23:45 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/fuzzing/fuzz_sddl_parse.c

index be85ce4f7eeb45882fc18c4c8e6981da7f5e92fa..05900b02e2fd1c0657aaf4ac9b8e056eb19c433f 100644 (file)
@@ -20,6 +20,7 @@
 #include "libcli/security/security.h"
 #include "librpc/gen_ndr/conditional_ace.h"
 #include "fuzzing/fuzzing.h"
+#include "util/charset/charset.h"
 
 #define MAX_LENGTH (100 * 1024 - 1)
 static char sddl_string[MAX_LENGTH + 1] = {0};
@@ -55,6 +56,28 @@ int LLVMFuzzerTestOneInput(const uint8_t *input, size_t len)
                goto end;
        }
        result = sddl_encode(mem_ctx, sd1, &dom_sid);
+       if (result == NULL) {
+               /*
+                * Because Samba currently doesn't enforce strict
+                * utf-8 parsing, illegal utf-8 sequences in
+                * sddl_string could have ferried bad characters
+                * through into the security descriptor conditions
+                * that we then find we can't encode.
+                *
+                * The proper solution is strict UTF-8 enforcement in
+                * sddl_decode, but for now we forgive unencodable
+                * security descriptors made from bad utf-8.
+                */
+               size_t byte_len, char_len, utf16_len;
+               ok = utf8_check(sddl_string, len,
+                               &byte_len, &char_len, &utf16_len);
+               if (!ok) {
+                       goto end;
+               }
+               /* utf-8 was fine, but we couldn't encode! */
+               abort();
+       }
+
        sd2 = sddl_decode(mem_ctx, result, &dom_sid);
        if (sd2 == NULL) {
                if (strlen(result) > CONDITIONAL_ACE_MAX_LENGTH) {