2020-06-05 13:49:25 +03:00
/*
* uri . c : a libFuzzer target to test the URI module .
*
* See Copyright for the status of this software .
*/
# include <libxml/uri.h>
# include "fuzz.h"
2023-03-08 15:59:03 +03:00
int
LLVMFuzzerInitialize ( int * argc ATTRIBUTE_UNUSED ,
char * * * argv ATTRIBUTE_UNUSED ) {
xmlFuzzMemSetup ( ) ;
xmlSetGenericErrorFunc ( NULL , xmlFuzzErrorFunc ) ;
return 0 ;
}
2020-06-05 13:49:25 +03:00
int
LLVMFuzzerTestOneInput ( const char * data , size_t size ) {
xmlURIPtr uri ;
2023-03-08 15:59:03 +03:00
size_t maxAlloc ;
const char * str1 , * str2 ;
char * copy ;
2023-12-10 16:46:59 +03:00
xmlChar * strRes ;
int intRes ;
2020-06-05 13:49:25 +03:00
2020-12-16 17:41:52 +03:00
if ( size > 10000 )
return ( 0 ) ;
2023-03-08 15:59:03 +03:00
xmlFuzzDataInit ( data , size ) ;
2023-12-10 16:46:59 +03:00
maxAlloc = xmlFuzzReadInt ( 4 ) % ( size * 8 + 100 ) ;
2023-03-08 15:59:03 +03:00
str1 = xmlFuzzReadString ( NULL ) ;
str2 = xmlFuzzReadString ( NULL ) ;
xmlFuzzMemSetLimit ( maxAlloc ) ;
2020-06-05 13:49:25 +03:00
2023-12-10 16:46:59 +03:00
xmlFuzzResetMallocFailed ( ) ;
intRes = xmlParseURISafe ( str1 , & uri ) ;
xmlFuzzCheckMallocFailure ( " xmlParseURISafe " , intRes = = - 1 ) ;
if ( uri ! = NULL ) {
xmlFuzzResetMallocFailed ( ) ;
strRes = xmlSaveUri ( uri ) ;
xmlFuzzCheckMallocFailure ( " xmlSaveURI " , strRes = = NULL ) ;
xmlFree ( strRes ) ;
xmlFreeURI ( uri ) ;
}
xmlFreeURI ( xmlParseURI ( str1 ) ) ;
2020-06-05 13:49:25 +03:00
2023-03-08 15:59:03 +03:00
uri = xmlParseURIRaw ( str1 , 1 ) ;
2020-06-05 13:49:25 +03:00
xmlFree ( xmlSaveUri ( uri ) ) ;
xmlFreeURI ( uri ) ;
2023-12-10 16:46:59 +03:00
xmlFuzzResetMallocFailed ( ) ;
strRes = BAD_CAST xmlURIUnescapeString ( str1 , - 1 , NULL ) ;
xmlFuzzCheckMallocFailure ( " xmlURIUnescapeString " ,
str1 ! = NULL & & strRes = = NULL ) ;
xmlFree ( strRes ) ;
2023-03-08 15:59:03 +03:00
xmlFree ( xmlURIEscape ( BAD_CAST str1 ) ) ;
2023-12-10 16:46:59 +03:00
xmlFuzzResetMallocFailed ( ) ;
strRes = xmlCanonicPath ( BAD_CAST str1 ) ;
xmlFuzzCheckMallocFailure ( " xmlCanonicPath " ,
str1 ! = NULL & & strRes = = NULL ) ;
xmlFree ( strRes ) ;
xmlFuzzResetMallocFailed ( ) ;
strRes = xmlPathToURI ( BAD_CAST str1 ) ;
xmlFuzzCheckMallocFailure ( " xmlPathToURI " , str1 ! = NULL & & strRes = = NULL ) ;
xmlFree ( strRes ) ;
xmlFuzzResetMallocFailed ( ) ;
intRes = xmlBuildURISafe ( BAD_CAST str2 , BAD_CAST str1 , & strRes ) ;
xmlFuzzCheckMallocFailure ( " xmlBuildURISafe " , intRes = = - 1 ) ;
xmlFree ( strRes ) ;
2020-06-05 13:49:25 +03:00
2023-03-08 15:59:03 +03:00
xmlFree ( xmlBuildURI ( BAD_CAST str2 , BAD_CAST str1 ) ) ;
2023-12-10 16:46:59 +03:00
xmlFuzzResetMallocFailed ( ) ;
intRes = xmlBuildRelativeURISafe ( BAD_CAST str2 , BAD_CAST str1 , & strRes ) ;
xmlFuzzCheckMallocFailure ( " xmlBuildRelativeURISafe " , intRes = = - 1 ) ;
xmlFree ( strRes ) ;
2023-03-08 15:59:03 +03:00
xmlFree ( xmlBuildRelativeURI ( BAD_CAST str2 , BAD_CAST str1 ) ) ;
2023-12-10 16:46:59 +03:00
xmlFuzzResetMallocFailed ( ) ;
strRes = xmlURIEscapeStr ( BAD_CAST str1 , BAD_CAST str2 ) ;
xmlFuzzCheckMallocFailure ( " xmlURIEscapeStr " ,
str1 ! = NULL & & strRes = = NULL ) ;
xmlFree ( strRes ) ;
2020-06-05 13:49:25 +03:00
2023-03-08 15:59:03 +03:00
copy = ( char * ) xmlCharStrdup ( str1 ) ;
xmlNormalizeURIPath ( copy ) ;
xmlFree ( copy ) ;
2020-06-05 13:49:25 +03:00
2023-03-08 15:59:03 +03:00
xmlFuzzMemSetLimit ( 0 ) ;
xmlFuzzDataCleanup ( ) ;
2020-06-05 13:49:25 +03:00
return 0 ;
}