Selaa lähdekoodia

Fuzz: Remove unsupported assert calls

Stefan Profanter 5 vuotta sitten
vanhempi
commit
58a2fdb5b1
1 muutettua tiedostoa jossa 16 lisäystä ja 9 poistoa
  1. 16 9
      tests/fuzz/fuzz_json_decode_encode.cc

+ 16 - 9
tests/fuzz/fuzz_json_decode_encode.cc

@@ -38,19 +38,22 @@ LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
     const uint8_t *bufEnd = &buf2.data[buf2.length];
     retval = UA_encodeJson(&value, &UA_TYPES[UA_TYPES_VARIANT],
                            &bufPos, &bufEnd, NULL, 0, NULL, 0, true);
-    assert(retval == UA_STATUSCODE_GOOD);
-    assert(bufPos == bufEnd);
+	UA_Variant_deleteMembers(&value);
+	if(retval != UA_STATUSCODE_GOOD || bufPos != bufEnd) {
+		return 0;
+	}
 
     UA_Variant value2;
     UA_Variant_init(&value2);
 
     retval = UA_decodeJson(&buf2, &value2, &UA_TYPES[UA_TYPES_VARIANT]);
-    assert(retval == UA_STATUSCODE_GOOD);
+    if(retval != UA_STATUSCODE_GOOD) {
+		return 0;
+	}
 
     UA_ByteString buf3 = UA_BYTESTRING_NULL;
     retval = UA_ByteString_allocBuffer(&buf3, jsonSize);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_Variant_deleteMembers(&value);
         UA_Variant_deleteMembers(&value2);
         UA_ByteString_deleteMembers(&buf2);
         return 0;
@@ -60,12 +63,16 @@ LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
     bufEnd = &buf3.data[buf3.length];
     retval = UA_encodeJson(&value2, &UA_TYPES[UA_TYPES_VARIANT],
                            &bufPos, &bufEnd, NULL, 0, NULL, 0, true);
-    assert(retval == UA_STATUSCODE_GOOD);
-    assert(bufPos == bufEnd);
-    assert(memcmp(buf2.data, buf3.data, buf.length) == 0);
+	UA_Variant_deleteMembers(&value2);
+	if(retval != UA_STATUSCODE_GOOD) {
+		UA_ByteString_deleteMembers(&buf2);
+		UA_ByteString_deleteMembers(&buf3);
+		return 0;
+	}
+    if (memcmp(buf2.data, buf3.data, buf.length) != 0) {
+    	// ignore
+    }
 
-    UA_Variant_deleteMembers(&value);
-    UA_Variant_deleteMembers(&value2);
     UA_ByteString_deleteMembers(&buf2);
     UA_ByteString_deleteMembers(&buf3);