|
1 |
| -// Copyright 2025 Google LLC |
2 |
| -// |
3 |
| -// Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
| -// you may not use this file except in compliance with the License. |
5 |
| -// You may obtain a copy of the License at |
6 |
| -// |
7 |
| -// http://www.apache.org/licenses/LICENSE-2.0 |
8 |
| -// |
9 |
| -// Unless required by applicable law or agreed to in writing, software |
10 |
| -// distributed under the License is distributed on an "AS IS" BASIS, |
11 |
| -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
| -// See the License for the specific language governing permissions and |
13 |
| -// limitations under the License. |
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
14 | 16 |
|
15 | 17 | const { FuzzedDataProvider } = require('@jazzer.js/core');
|
16 | 18 |
|
17 | 19 | function LLVMFuzzerTestOneInput(data) {
|
18 | 20 | if (!data || data.length === 0) return 0;
|
19 | 21 |
|
20 | 22 | const fdp = new FuzzedDataProvider(data);
|
21 |
| - const input = fdp.consumeString(data.length); |
22 | 23 |
|
23 | 24 | try {
|
24 |
| - // HTTP header parsing fuzzing |
25 |
| - const headers = input.split('\n'); |
26 |
| - for (const header of headers) { |
27 |
| - if (header.includes(':')) { |
28 |
| - const [name, value] = header.split(':', 2); |
29 |
| - if (name && value) { |
30 |
| - // Basic header validation that doesn't crash |
31 |
| - const trimmedName = name.trim(); |
32 |
| - const trimmedValue = value.trim(); |
33 |
| - if (trimmedName.length > 0 && trimmedValue.length > 0) { |
34 |
| - // Success - valid header format |
35 |
| - } |
| 25 | + // Test HTTP header parsing with fuzzed input |
| 26 | + const input = fdp.consumeString(data.length); |
| 27 | + if (input.includes(':')) { |
| 28 | + const parts = input.split(':', 2); |
| 29 | + if (parts.length === 2) { |
| 30 | + const headerName = parts[0].trim(); |
| 31 | + const headerValue = parts[1].trim(); |
| 32 | + // Basic header validation |
| 33 | + if (headerName && headerValue) { |
| 34 | + // Header parsing logic would go here |
36 | 35 | }
|
37 | 36 | }
|
38 | 37 | }
|
39 |
| - } catch (_) { |
40 |
| - // Expected parsing errors |
| 38 | + } catch (error) { |
| 39 | + // Expected parsing errors are fine |
41 | 40 | }
|
42 | 41 |
|
43 | 42 | return 0;
|
44 | 43 | }
|
45 | 44 |
|
46 |
| -module.exports = { LLVMFuzzerTestOneInput }; |
| 45 | +module.exports = { LLVMFuzzerTestOneInput }; |
0 commit comments