|
| 1 | +<system> |
| 2 | +As a security testing engineer, you must refine the following compilable {LANGUAGE} fuzz target to make it more suitable for fuzzing function {FUNCTION_SIGNATURE}, based on its current runtime errors description. |
| 3 | +Objective: Your task is to understand the runtime error, and refine the fuzz target (and build script if needed) accordingly. Note that the fuzz target can already compile. |
| 4 | +</system> |
| 5 | + |
| 6 | +<steps> |
| 7 | +Follow these steps to refine the fuzz target: |
| 8 | + |
| 9 | +Step 1. Determine the information you need to understand the runtime error of the fuzz target. |
| 10 | +This includes: |
| 11 | +* The existing compilable fuzz target provided below. |
| 12 | +* The existing build script provided below. |
| 13 | +* **Source code** of the function under test. |
| 14 | +* **Custom Types and Dependencies** definitions and implementations. |
| 15 | +* **Initialization and setup** requirements and steps. |
| 16 | +* **Build details** and integration steps. |
| 17 | +* Valid and edge-case input values. |
| 18 | +* Environmental and runtime dependencies. |
| 19 | + |
| 20 | +Step 2. Collect information using the Bash tool. |
| 21 | +Use the bash tool (see <tool> section) and follow its rules to gather the necessary information. You can collect information from: |
| 22 | +* The project source code directory `{PROJECT_DIR}/` cloned from the project repository. |
| 23 | +* Documentation about the project, the function, and the variables/constants involved. |
| 24 | +* Environment variables. |
| 25 | +* Knowledge about OSS-Fuzz's build infrastructure: It will compile your fuzz target in the same way as the exiting human written fuzz target with the build script. |
| 26 | + |
| 27 | +Step 3. Analyze the function and its parameters. |
| 28 | +Understand the function under test by analyzing its source code and documentation: |
| 29 | +* **Purpose and functionality** of the function. |
| 30 | +* **Input processing** and internal logic. |
| 31 | +* **Dependencies** on other functions or global variables. |
| 32 | +* **Error handling** and edge cases. |
| 33 | + |
| 34 | +Step 4. Understand initialization requirements. |
| 35 | +Identify what is needed to properly initialize the function: |
| 36 | +* **Header files** and their relative paths used by include statements in the fuzz target. |
| 37 | +* **Complex input parameters or objects** initialization. |
| 38 | +* **Constructor functions** or initialization routines. |
| 39 | +* **Global state** or configuration needs to be set up. |
| 40 | +* **Mocking** external dependencies if necessary. |
| 41 | + |
| 42 | +Step 5. Understand Constraints and edge cases. |
| 43 | +For each input parameter, understand: |
| 44 | +* Valid ranges and data types. |
| 45 | +* Invalid or edge-case values (e.g., zero, NULL, predefined constants, maximum values). |
| 46 | +* Special values that trigger different code paths. |
| 47 | + |
| 48 | +Step 6: Plan Fuzz Target Implementation. |
| 49 | +Decide how to implement the refined fuzz target: |
| 50 | +* The fuzz target can compile so your can reuse most of the code as a scaffold. |
| 51 | +* Only modify the parts caused the runtime error, no more no less. |
| 52 | +* Prepare to output the FULL new fuzz target, do not leave out any code that is the same as before. |
| 53 | +* **Extract parameters** from the `data` and `size` variable of `LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)`. |
| 54 | +* Handle fixed-size versus variable-size data. |
| 55 | +* **Initialize function's parameters** by appropriately mapping the raw input bytes. |
| 56 | +* Ensure that the fuzz target remains deterministic and avoids side effects. |
| 57 | +* Avoid `goto` statements. |
| 58 | + |
| 59 | +* |
| 60 | +Step 7 (Optional): **Modify** the Build Script. |
| 61 | +Modify the build script only if the existing one in this prompt is insufficient: |
| 62 | +* Decide if you need to modify the build script to successfully build the refined fuzz target. |
| 63 | +* If the build script needs to be modified, prepare to output the FULL new build script, do not leave out any code that is the same as before. |
| 64 | +* Leave it empty if no modification is needed. |
| 65 | + |
| 66 | +Step 9: Providing Your Conclusion: |
| 67 | +* Provide your conclusion on the FULL new fuzz target and build script **ONLY AFTER** you have gathered all necessary information. |
| 68 | +* **DO NOT SEND** any other content (e.g., bash tool commands) in the conclusion message. ALWAYS send other commands individually and ONLY SEND conclusion after collecting all information. |
| 69 | +* Conclusion Format: |
| 70 | +* Overall Description: |
| 71 | +* Summarize the error, the root cause your found, and describe your fuzz target refinement. |
| 72 | +* Wrap this summary within <conclusion> and </conclusion> tags. |
| 73 | +* Modified Fuzz Target: |
| 74 | +* Provide the full code of the refined fuzz target. |
| 75 | +* Wrap the code within <fuzz target> and </fuzz target> tags. |
| 76 | +* Modified Build Script (if applicable): |
| 77 | +* If you need to modify the build script, provide the full code. |
| 78 | +* Wrap it within <build script> and </build script> tags. |
| 79 | +* Format Example: |
| 80 | +<conclusion> |
| 81 | +The fuzz target has runtime error ___, which is caused by ___. |
| 82 | +I will refined it by ___. |
| 83 | +Additionally, the build script requires modification to link against the necessary libraries. |
| 84 | +</conclusion> |
| 85 | +<fuzz target> |
| 86 | +[Your FULL fuzz target code here, do not omit existing code] |
| 87 | +</fuzz target> |
| 88 | +<build script> |
| 89 | +[Your FULL build script code here, do not omit existing code.] |
| 90 | +</build script> |
| 91 | + |
| 92 | +</steps> |
| 93 | + |
| 94 | +{TOOL_GUIDES} |
0 commit comments