mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-10-24 11:54:53 +00:00
fuzzing: Fuzz different print methods
This is achieved by encoding the type of function used in the first two bytes. First byte: b: buffered Second byte: f: formatted
This commit is contained in:
1 parent
4785070ad3
commit
c5a09a32a9
15 files changed
+117
-17
No files matched your search
+25
-3
@@ -101,12 +101,12 @@ int main(int argc, char** argv)
|
||||
filename = argv[1];
|
||||
|
||||
json = read_file(filename);
|
||||
if (json == NULL)
|
||||
if ((json == NULL) || (json[0] == '\0') || (json[1] == '\0'))
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
goto cleanup;
|
||||
}
|
||||
item = cJSON_Parse(json);
|
||||
item = cJSON_Parse(json + 2);
|
||||
if (item == NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
@@ -114,7 +114,29 @@ int main(int argc, char** argv)
|
||||
|
||||
if ((argc == 3) && (strncmp(argv[2], "yes", 3) == 0))
|
||||
{
|
||||
printed_json = cJSON_Print(item);
|
||||
int do_format = 0;
|
||||
if (json[1] == 'f')
|
||||
{
|
||||
do_format = 1;
|
||||
}
|
||||
|
||||
if (json[0] == 'b')
|
||||
{
|
||||
/* buffered printing */
|
||||
printed_json = cJSON_PrintBuffered(item, 1, do_format);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unbuffered printing */
|
||||
if (do_format)
|
||||
{
|
||||
printed_json = cJSON_Print(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
printed_json = cJSON_PrintUnformatted(item);
|
||||
}
|
||||
}
|
||||
if (printed_json == NULL)
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
|
||||
Reference in new issue
Block a user