From: K.Kosako Date: Fri, 30 Aug 2019 00:25:14 +0000 (+0900) Subject: add internal error code check X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2a6577e7364cb85138c518f3ef499b3efff2d00;p=onig add internal error code check --- diff --git a/harnesses/encode-harness.c b/harnesses/encode-harness.c index 26cab6d..af05e41 100644 --- a/harnesses/encode-harness.c +++ b/harnesses/encode-harness.c @@ -3,10 +3,15 @@ * contributed by Mark Griffin */ #include -#include "oniguruma.h" - +#include #include #include +#include +#include +#include + +#include "oniguruma.h" + #define PARSE_DEPTH_LIMIT 120 #define RETRY_LIMIT 3500 @@ -73,7 +78,15 @@ exec(OnigEncoding enc, OnigOptionType options, onig_error_code_to_str((UChar* )s, r, &einfo); fprintf(stdout, "ERROR: %s\n", s); onig_end(); - return -1; + + if (r == ONIGERR_PARSER_BUG || + r == ONIGERR_STACK_BUG || + r == ONIGERR_UNDEFINED_BYTECODE || + r == ONIGERR_UNEXPECTED_BYTECODE) { + return -2; + } + else + return -1; } if (onigenc_is_valid_mbc_string(enc, str, end) != 0) { @@ -85,6 +98,28 @@ exec(OnigEncoding enc, OnigOptionType options, return 0; } +#if 0 +static void +output_data(char* path, const uint8_t * data, size_t size) +{ + int fd; + ssize_t n; + + fd = open(path, O_CREAT|O_RDWR, S_IRUSR|S_IRGRP|S_IROTH); + if (fd == -1) { + fprintf(stderr, "ERROR: output_data(): can't open(%s)\n", path); + return ; + } + + n = write(fd, (const void* )data, size); + if (n != size) { + fprintf(stderr, "ERROR: output_data(): n: %ld, size: %ld\n", n, size); + } + close(fd); +} +#endif + + #define PATTERN_SIZE 32 #define NUM_CONTROL_BYTES 1 #define MIN_STR_SIZE 1 @@ -165,13 +200,16 @@ int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size) free(pattern); free(str); + if (r == -2) { + //output_data("parser-bug", Data, Size); + exit(-2); + } + return r; } #ifdef WITH_READ_MAIN -#include - extern int main(int argc, char* argv[]) { size_t n;