Fuzzing of native http1 parser

This commit is contained in:
Olof hagsand 2022-02-08 21:26:53 +01:00
parent 4aa74fa1d8
commit 51fd973642
8 changed files with 132 additions and 6 deletions

View file

@ -279,13 +279,13 @@ absolute_paths : absolute_paths absolute_path
{
if (($$ = clixon_string_del_join($1, "/", $2)) == NULL) { free($2); YYABORT;}
free($2);
_PARSE_DEBUG("absolute-paths -> absolute-paths absolute -path");
_PARSE_DEBUG("absolute-paths -> absolute-paths absolute-path");
}
| absolute_path
{
if (($$ = clixon_string_del_join(NULL, "/", $1)) == NULL) { free($1); YYABORT;}
free($1);
_PARSE_DEBUG("absolute-paths -> absolute -path");
_PARSE_DEBUG("absolute-paths -> absolute-path");
}
;
@ -326,10 +326,12 @@ header_fields : header_fields header_field CRLF
field-name = token */
header_field : TOKEN COLON ows field_values ows
{
if (http1_parse_header_field(_HY, $1, $4) < 0)
YYABORT;
if ($4){
if (http1_parse_header_field(_HY, $1, $4) < 0)
YYABORT;
free($4);
}
free($1);
free($4);
_PARSE_DEBUG("header-field -> field-name : field-values");
}
;
@ -342,7 +344,7 @@ field_values : field_vchars
$$ = $1; // XXX is there more than one??
_PARSE_DEBUG("field-values -> field-values field-vchars");
}
| { _PARSE_DEBUG("field-values -> "); }
| { $$ = NULL; _PARSE_DEBUG("field-values -> "); }
;

View file

@ -1400,6 +1400,11 @@ usage(clicon_handle h,
exit(0);
}
/* Enable for normal use
* Disable for unit testing, fuzzing, etc
*/
#if 1
int
main(int argc,
char **argv)
@ -1602,3 +1607,42 @@ main(int argc,
restconf_terminate(h);
return retval;
}
#else /* Unit test */
int
main(int argc,
char **argv)
{
int retval = -1;
clicon_handle h = NULL;
restconf_conn *rc;
int dbg = 0;
int c;
while ((c = getopt(argc, argv, "hD:")) != -1)
switch (c) {
case 'h':
fprintf(stderr, "%s [-h] [-D <dbg>]\n", argv[0]);
break;
case 'D' : /* debug. Note this overrides any setting in the config */
if (sscanf(optarg, "%d", &dbg) != 1)
fprintf(stderr, "%s [-h] [-D <dbg>]\n", argv[0]);
break;
}
if ((h = restconf_handle_init()) == NULL)
goto done;
clicon_log_init(__FILE__, LOG_DEBUG, CLICON_LOG_STDERR);
clicon_debug_init(dbg, NULL);
if ((rc = restconf_conn_new(h, 0)) == NULL)
goto done;
if (restconf_stream_data_new(rc, 0) == NULL)
goto done;
if (clixon_http1_parse_file(h, rc, stdin, "stdin") < 0)
goto done;
retval = 0;
done:
return retval;
}
#endif