You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
2.6 KiB
184 lines
2.6 KiB
/*
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
void exit_bo_good_unreachable_bad() {
|
|
int arr[1];
|
|
exit(1);
|
|
// unreachable so no buffer overrun
|
|
arr[42] = 42;
|
|
}
|
|
|
|
void fgetc_m1_bad(FILE* f) {
|
|
int arr[10000];
|
|
int c = fgetc(f);
|
|
arr[c] = 42;
|
|
}
|
|
|
|
void fgetc_255_bad(FILE* f) {
|
|
int arr[255];
|
|
int c = fgetc(f);
|
|
if (c >= 0) {
|
|
arr[c] = 42;
|
|
}
|
|
}
|
|
|
|
void fgetc_256_good(FILE* f) {
|
|
int arr[256];
|
|
int c = fgetc(f);
|
|
if (c >= 0) {
|
|
arr[c] = 42;
|
|
}
|
|
}
|
|
|
|
void fgetc_256_bad(FILE* f) {
|
|
int arr[256];
|
|
int c = fgetc(f);
|
|
arr[c + 1] = 42;
|
|
}
|
|
|
|
void fgetc_257_good(FILE* f) {
|
|
int arr[257];
|
|
int c = fgetc(f);
|
|
arr[c + 1] = 42;
|
|
}
|
|
|
|
void memcpy_bad1() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr1, arr2, 44);
|
|
}
|
|
|
|
void memcpy_bad2() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr2, arr1, 44);
|
|
}
|
|
|
|
void memcpy_bad3() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr1, arr2, -1);
|
|
}
|
|
|
|
void memcpy_bad4() {
|
|
int src[1];
|
|
int buff[1];
|
|
int* dst = &buff[0];
|
|
memcpy(dst, src, sizeof(dst));
|
|
}
|
|
|
|
void memcpy_good1() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr2, arr1, 40);
|
|
}
|
|
|
|
void memcpy_good2() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr2, arr1, 0);
|
|
}
|
|
|
|
void memcpy_good3() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memcpy(arr2, arr1, 20);
|
|
}
|
|
|
|
void memcpy_good4() {
|
|
int src[3];
|
|
int dst[3];
|
|
memcpy(dst, src, sizeof(dst));
|
|
}
|
|
|
|
void memmove_bad1() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr1, arr2, 44);
|
|
}
|
|
|
|
void memmove_bad2() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr2, arr1, 44);
|
|
}
|
|
|
|
void memmove_bad3() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr1, arr2, -1);
|
|
}
|
|
|
|
void memmove_bad4() {
|
|
int src[1];
|
|
int buff[1];
|
|
int* dst = &buff[0];
|
|
memmove(dst, src, sizeof(dst));
|
|
}
|
|
|
|
void memmove_good1() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr2, arr1, 40);
|
|
}
|
|
|
|
void memmove_good2() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr2, arr1, 0);
|
|
}
|
|
|
|
void memmove_good3() {
|
|
int arr1[10];
|
|
int arr2[20];
|
|
memmove(arr2, arr1, 20);
|
|
}
|
|
|
|
void memmove_good4() {
|
|
int src[3];
|
|
int dst[3];
|
|
memmove(dst, src, sizeof(dst));
|
|
}
|
|
|
|
void memset_bad1() {
|
|
int arr[10];
|
|
memset(arr, 0, 44);
|
|
}
|
|
|
|
void memset_bad2() {
|
|
int arr[10];
|
|
memset(arr, 0, -1);
|
|
}
|
|
|
|
void memset_bad3() {
|
|
int arr[1];
|
|
int* dst = &arr[0];
|
|
memset(dst, 0, sizeof(dst));
|
|
}
|
|
|
|
void memset_good1() {
|
|
int arr[10];
|
|
memset(arr, 0, 40);
|
|
}
|
|
|
|
void memset_good2() {
|
|
int arr[10];
|
|
memset(arr, 0, 0);
|
|
}
|
|
|
|
void memset_good3() {
|
|
int arr[10];
|
|
memset(arr, 0, 20);
|
|
}
|
|
|
|
void memset_good4() {
|
|
int arr[10];
|
|
memset(arr, 0, sizeof(arr));
|
|
}
|