Skip to content

Commit fc16b70

Browse files
authored
Format C (#1602)
1 parent a9014a9 commit fc16b70

File tree

13 files changed

+169
-183
lines changed

13 files changed

+169
-183
lines changed

fuzzers/baby_fuzzer_swap_differential/common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
bool both_require(const uint8_t *bytes, size_t len) {
44
if (len >= 1 && bytes[0] == 'a') {
55
if (len >= 2 && bytes[1] == 'b') {
6-
if (len >= 3 && bytes[2] == 'c') {
7-
return ACCEPT;
8-
}
6+
if (len >= 3 && bytes[2] == 'c') { return ACCEPT; }
97
}
108
}
119
return REJECT;

fuzzers/baby_fuzzer_swap_differential/first.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
bool inspect_first(const uint8_t *bytes, size_t len) {
44
if (both_require(bytes, len)) {
5-
if (len >= 4 && bytes[3] == 'd') {
6-
return ACCEPT;
7-
}
5+
if (len >= 4 && bytes[3] == 'd') { return ACCEPT; }
86
}
97
return REJECT;
108
}

fuzzers/baby_fuzzer_swap_differential/second.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
bool inspect_second(const uint8_t *bytes, size_t len) {
44
if (both_require(bytes, len)) {
5-
if (len >= 5 && bytes[4] == 'e') {
6-
return ACCEPT;
7-
}
5+
if (len >= 5 && bytes[4] == 'e') { return ACCEPT; }
86
}
97
return REJECT;
108
}

fuzzers/fuzzbench/fuzz.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
66
if (Size >= 8 && *(uint32_t *)Data == 0xaabbccdd) { abort(); }
77
char buf[8] = {'a', 'b', 'c', 'd'};
88

9-
if (memcmp(Data, buf, 4) == 0) {
10-
abort();
11-
}
9+
if (memcmp(Data, buf, 4) == 0) { abort(); }
1210
return 0;
1311
}
1412

fuzzers/fuzzbench/stub_rt.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
#include <stdint.h>
22

3-
__attribute__ ((weak)) void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) {
3+
__attribute__((weak)) void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,
4+
uint32_t *stop) {
45
}
56

6-
__attribute__ ((weak)) void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
7+
__attribute__((weak)) void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
78
}
89

9-
__attribute__ ((weak)) void __cmplog_rtn_hook(uint8_t *ptr1, uint8_t *ptr2) {
10+
__attribute__((weak)) void __cmplog_rtn_hook(uint8_t *ptr1, uint8_t *ptr2) {
1011
}
1112

12-
__attribute__ ((weak)) void __cmplog_rtn_gcc_stdstring_cstring(uint8_t *stdstring, uint8_t *cstring) {
13+
__attribute__((weak)) void __cmplog_rtn_gcc_stdstring_cstring(
14+
uint8_t *stdstring, uint8_t *cstring) {
1315
}
1416

15-
__attribute__ ((weak)) void __cmplog_rtn_gcc_stdstring_stdstring(uint8_t *stdstring1, uint8_t *stdstring2) {
17+
__attribute__((weak)) void __cmplog_rtn_gcc_stdstring_stdstring(
18+
uint8_t *stdstring1, uint8_t *stdstring2) {
1619
}
1720

18-
__attribute__ ((weak)) void __cmplog_rtn_llvm_stdstring_cstring(uint8_t *stdstring, uint8_t *cstring) {
21+
__attribute__((weak)) void __cmplog_rtn_llvm_stdstring_cstring(
22+
uint8_t *stdstring, uint8_t *cstring) {
1923
}
2024

21-
__attribute__ ((weak)) void __cmplog_rtn_llvm_stdstring_stdstring(uint8_t *stdstring1, uint8_t *stdstring2) {
25+
__attribute__((weak)) void __cmplog_rtn_llvm_stdstring_stdstring(
26+
uint8_t *stdstring1, uint8_t *stdstring2) {
2227
}
2328

2429
extern void libafl_main(void);
2530

26-
int main(int argc, char **argv) { libafl_main(); return 0; }
31+
int main(int argc, char **argv) {
32+
libafl_main();
33+
return 0;
34+
}

fuzzers/libfuzzer_stb_image/harness.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1313
int x, y, channels;
1414

15-
if (!stbi_info_from_memory(data, size, &x, &y, &channels)) {return 0;}
15+
if (!stbi_info_from_memory(data, size, &x, &y, &channels)) { return 0; }
1616

1717
/* exit if the image is larger than ~80MB */
18-
if (y && x > (80000000 / 4) / y){ return 0;}
18+
if (y && x > (80000000 / 4) / y) { return 0; }
1919

2020
unsigned char *img = stbi_load_from_memory(data, size, &x, &y, &channels, 4);
2121

22-
free(img);
23-
24-
// if (x > 10000) free(img); // free crash
22+
free(img);
23+
24+
// if (x > 10000) free(img); // free crash
2525

2626
// if (x > 10000) {free(img);} // free crash
2727

fuzzers/qemu_systemmode/example/main.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
int BREAKPOINT() {
2-
for (;;)
3-
{
4-
}
2+
for (;;) {}
53
}
64

7-
int LLVMFuzzerTestOneInput(unsigned int* Data, unsigned int Size) {
8-
//if (Data[3] == 0) {while(1){}} // cause a timeout
9-
for (int i=0; i<Size; i++) {
10-
//if (Data[i] > 0xFFd0 && Data[i] < 0xFFFF) {return 1;} // cause qemu to crash
11-
for (int j=i+1; j<Size; j++) {
12-
if (Data[j] == 0) {continue;}
13-
if (Data[j]>Data[i]) {
5+
int LLVMFuzzerTestOneInput(unsigned int *Data, unsigned int Size) {
6+
// if (Data[3] == 0) {while(1){}} // cause a timeout
7+
for (int i = 0; i < Size; i++) {
8+
// if (Data[i] > 0xFFd0 && Data[i] < 0xFFFF) {return 1;} // cause qemu to
9+
// crash
10+
for (int j = i + 1; j < Size; j++) {
11+
if (Data[j] == 0) { continue; }
12+
if (Data[j] > Data[i]) {
1413
int tmp = Data[i];
15-
Data[i]=Data[j];
16-
Data[j]=tmp;
17-
if (Data[i] <= 100) {j--;}
14+
Data[i] = Data[j];
15+
Data[j] = tmp;
16+
if (Data[i] <= 100) { j--; }
1817
}
1918
}
2019
}
2120
return BREAKPOINT();
2221
}
23-
unsigned int FUZZ_INPUT[] = {
24-
101,201,700,230,860,
25-
234,980,200,340,678,
26-
230,134,900,236,900,
27-
123,800,123,658,607,
28-
246,804,567,568,207,
29-
407,246,678,457,892,
30-
834,456,878,246,699,
31-
854,234,844,290,125,
32-
324,560,852,928,910,
33-
790,853,345,234,586,
34-
};
22+
unsigned int FUZZ_INPUT[] = {
23+
101, 201, 700, 230, 860, 234, 980, 200, 340, 678, 230, 134, 900,
24+
236, 900, 123, 800, 123, 658, 607, 246, 804, 567, 568, 207, 407,
25+
246, 678, 457, 892, 834, 456, 878, 246, 699, 854, 234, 844, 290,
26+
125, 324, 560, 852, 928, 910, 790, 853, 345, 234, 586,
27+
};
3528

3629
int main() {
3730
LLVMFuzzerTestOneInput(FUZZ_INPUT, 50);

fuzzers/qemu_systemmode/example/startup.c

Lines changed: 77 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
* FreeRTOS V202112.00
33
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
* this software and associated documentation files (the "Software"), to deal in
7-
* the Software without restriction, including without limitation the rights to
8-
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
* the Software, and to permit persons to whom the Software is furnished to do so,
10-
* subject to the following conditions:
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
1111
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
1414
*
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
2122
*
2223
* https://www.FreeRTOS.org
2324
* https://github.com/FreeRTOS
@@ -31,84 +32,76 @@ extern int main();
3132
extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss;
3233

3334
/* Prevent optimization so gcc does not replace code with memcpy */
34-
__attribute__( ( optimize( "O0" ) ) )
35-
__attribute__( ( naked ) )
36-
void Reset_Handler( void )
37-
{
38-
/* set stack pointer */
39-
__asm volatile ( "ldr r0, =_estack" );
40-
__asm volatile ( "mov sp, r0" );
35+
__attribute__((optimize("O0"))) __attribute__((naked)) void Reset_Handler(
36+
void) {
37+
/* set stack pointer */
38+
__asm volatile("ldr r0, =_estack");
39+
__asm volatile("mov sp, r0");
4140

42-
/* copy .data section from flash to RAM */
43-
// Not needed for this example, see linker script
44-
// for( uint32_t * src = &_sidata, * dest = &_sdata; dest < &_edata; )
45-
// {
46-
// *dest++ = *src++;
47-
// }
41+
/* copy .data section from flash to RAM */
42+
// Not needed for this example, see linker script
43+
// for( uint32_t * src = &_sidata, * dest = &_sdata; dest < &_edata; )
44+
// {
45+
// *dest++ = *src++;
46+
// }
4847

49-
/* zero out .bss section */
50-
for( uint32_t * dest = &_sbss; dest < &_ebss; )
51-
{
52-
*dest++ = 0;
53-
}
48+
/* zero out .bss section */
49+
for (uint32_t *dest = &_sbss; dest < &_ebss;) {
50+
*dest++ = 0;
51+
}
5452

55-
/* jump to board initialisation */
56-
void _start( void );
57-
_start();
53+
/* jump to board initialisation */
54+
void _start(void);
55+
_start();
5856
}
5957

60-
const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) =
61-
{
62-
( uint32_t * ) &_estack,
63-
( uint32_t * ) &Reset_Handler, /* Reset -15 */
64-
0, /* NMI_Handler -14 */
65-
0, /* HardFault_Handler -13 */
66-
0, /* MemManage_Handler -12 */
67-
0, /* BusFault_Handler -11 */
68-
0, /* UsageFault_Handler -10 */
69-
0, /* reserved */
70-
0, /* reserved */
71-
0, /* reserved */
72-
0, /* reserved -6 */
73-
0, /* SVC_Handler -5 */
74-
0, /* DebugMon_Handler -4 */
75-
0, /* reserved */
76-
0, /* PendSV handler -2 */
77-
0, /* SysTick_Handler -1 */
78-
0, /* uart0 receive 0 */
79-
0, /* uart0 transmit */
80-
0, /* uart1 receive */
81-
0, /* uart1 transmit */
82-
0, /* uart 2 receive */
83-
0, /* uart 2 transmit */
84-
0, /* GPIO 0 combined interrupt */
85-
0, /* GPIO 2 combined interrupt */
86-
0, /* Timer 0 */
87-
0, /* Timer 1 */
88-
0, /* Dial Timer */
89-
0, /* SPI0 SPI1 */
90-
0, /* uart overflow 1, 2,3 */
91-
0, /* Ethernet 13 */
58+
const uint32_t *isr_vector[] __attribute__((section(".isr_vector"))) = {
59+
(uint32_t *)&_estack,
60+
(uint32_t *)&Reset_Handler, /* Reset -15 */
61+
0, /* NMI_Handler -14 */
62+
0, /* HardFault_Handler -13 */
63+
0, /* MemManage_Handler -12 */
64+
0, /* BusFault_Handler -11 */
65+
0, /* UsageFault_Handler -10 */
66+
0, /* reserved */
67+
0, /* reserved */
68+
0, /* reserved */
69+
0, /* reserved -6 */
70+
0, /* SVC_Handler -5 */
71+
0, /* DebugMon_Handler -4 */
72+
0, /* reserved */
73+
0, /* PendSV handler -2 */
74+
0, /* SysTick_Handler -1 */
75+
0, /* uart0 receive 0 */
76+
0, /* uart0 transmit */
77+
0, /* uart1 receive */
78+
0, /* uart1 transmit */
79+
0, /* uart 2 receive */
80+
0, /* uart 2 transmit */
81+
0, /* GPIO 0 combined interrupt */
82+
0, /* GPIO 2 combined interrupt */
83+
0, /* Timer 0 */
84+
0, /* Timer 1 */
85+
0, /* Dial Timer */
86+
0, /* SPI0 SPI1 */
87+
0, /* uart overflow 1, 2,3 */
88+
0, /* Ethernet 13 */
9289
};
9390

94-
__attribute__( ( naked ) ) void exit(__attribute__((unused)) int status )
95-
{
96-
/* Force qemu to exit using ARM Semihosting */
97-
__asm volatile (
98-
"mov r1, r0\n"
99-
"cmp r1, #0\n"
100-
"bne .notclean\n"
101-
"ldr r1, =0x20026\n" /* ADP_Stopped_ApplicationExit, a clean exit */
102-
".notclean:\n"
103-
"movs r0, #0x18\n" /* SYS_EXIT */
104-
"bkpt 0xab\n"
105-
"end: b end\n"
106-
);
91+
__attribute__((naked)) void exit(__attribute__((unused)) int status) {
92+
/* Force qemu to exit using ARM Semihosting */
93+
__asm volatile(
94+
"mov r1, r0\n"
95+
"cmp r1, #0\n"
96+
"bne .notclean\n"
97+
"ldr r1, =0x20026\n" /* ADP_Stopped_ApplicationExit, a clean exit */
98+
".notclean:\n"
99+
"movs r0, #0x18\n" /* SYS_EXIT */
100+
"bkpt 0xab\n"
101+
"end: b end\n");
107102
}
108103

109-
void _start( void )
110-
{
111-
main( );
112-
exit( 0 );
104+
void _start(void) {
105+
main();
106+
exit(0);
113107
}
114-

0 commit comments

Comments
 (0)