-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fuzzer] Use puts() rather than printf() in CopyFileToErr()
CopyFileToErr() uses Printf("%s", ...) which fails with a negative size on files >2Gb (Its path is through var-args wrappers to an unnecessary "%s" expansion and subject to int overflows) Using puts() in place of printf() bypasses this path and writes the string directly to stderr. This avoids the present loss of data when a crashed worker has generated >2Gb of output. rdar://99384640 Reviewed By: yln Differential Revision: https://reviews.llvm.org/D146189
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
#include "FuzzerIO.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
assert(argc == 2); | ||
const char *FileName = argv[1]; | ||
FILE *f = fopen(FileName, "w"); | ||
|
||
// This is the biggest file possible unless CopyFileToErr() uses Puts() | ||
fprintf(f, "%2147483646s", "2Gb-2"); | ||
|
||
// This makes the file too big if CopyFileToErr() uses fprintf("%s", <file>) | ||
fprintf(f, "THIS LINE RESPONSIBLE FOR EXCEEDING 2Gb FILE SIZE\n"); | ||
fclose(f); | ||
|
||
// Should now because CopyFileToErr() now uses Puts() | ||
fuzzer::CopyFileToErr(FileName); | ||
|
||
// File is >2Gb so clean up | ||
remove(FileName); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RUN: %cpp_compiler %S/BigFileCopy.cpp -o %t | ||
RUN: %run %t big-file.txt 2>big-file-out.txt; result=$? | ||
RUN: %run rm -f big-file.txt big-file-out.txt | ||
RUN: %run (exit $result) |