mirror of https://github.com/google/oss-fuzz.git
47 lines
1.4 KiB
C
47 lines
1.4 KiB
C
/* Copyright 2021 Google LLC
|
|
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 <sys/types.h>
|
|
#include <sys/socket.h>
|
|
|
|
// Forward declared because we want to use FuzzedDataProvider,
|
|
// which requires CPP.
|
|
extern ssize_t fuzz_get_random_data(void *buf, size_t len);
|
|
ssize_t fuzz_recv(int sockfd, void *buf, size_t len, int flags){
|
|
return fuzz_get_random_data(buf, len);
|
|
}
|
|
|
|
ssize_t fuzz_read(int sockfd, void *buf, size_t len){
|
|
return fuzz_get_random_data(buf, len);
|
|
}
|
|
|
|
char *fuzz_fgets(char *s, int size, FILE *stream) {
|
|
ssize_t v = fuzz_get_random_data(s, size-1);
|
|
if (s[0] == '\0') {
|
|
s[0] = 'A';
|
|
}
|
|
s[size-1] = '\0';
|
|
return s;
|
|
}
|
|
|
|
|
|
int fuzz_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout) {
|
|
char val;
|
|
ssize_t c = fuzz_get_random_data(&val, 1);
|
|
return c;
|
|
}
|
|
|
|
|
|
ssize_t fuzz_send(int sockfd, const void *buf, size_t len, int flags) {
|
|
return len;
|
|
}
|