Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions projects/libcups/fuzzer/fuzzhttp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright The libcups Developers.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "cups.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if (size == 0 || size > 65536)
return 0;

// NUL-terminate the input so it can be used as a C string.
char *str = (char *)malloc(size + 1);
if (!str)
return 0;
memcpy(str, data, size);
str[size] = '\0';

// 1. URI parser: scheme://user@host:port/resource splitter.
char scheme[256], username[256], host[256], resource[1024];
int port = 0;
http_uri_status_t st = httpSeparateURI(HTTP_URI_CODING_ALL, str,
scheme, sizeof(scheme),
username, sizeof(username),
host, sizeof(host),
&port,
resource, sizeof(resource));

// Round-trip the separated components back into a URI.
if (st == HTTP_URI_STATUS_OK)
{
char rebuilt[2048];
httpAssembleURI(HTTP_URI_CODING_ALL, rebuilt, sizeof(rebuilt),
scheme, username, host, port, resource);
}

// 2. base64 decoder (output is at most ~3/4 of the input).
{
size_t outlen = size;
char *out = (char *)malloc(outlen + 1);
if (out)
{
const char *end = NULL;
httpDecode64(out, &outlen, str, &end);
free(out);
}
}

// 3. HTTP date-string parser.
httpGetDateTime(str);

free(str);
return 0;
}
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/base64
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SGVsbG8sIFdvcmxkIQ==
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/httpdate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sun, 06 Nov 1994 08:49:37 GMT
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/uri_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file:///var/spool/cups/data
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/uri_http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://example.com:80/path/to/res?q=1&x=2#frag
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/uri_ipps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ipps://user:pass@printer.example.com:631/ipp/print
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/uri_mailto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mailto:admin@example.com
1 change: 1 addition & 0 deletions projects/libcups/seeds/fuzzhttp_seed_corpus/uri_socket
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
socket://192.168.0.10:9100