mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 02:36:06 +00:00
improve Path::makeUnique when mkstemp/mktemp are not available
patch by Lasse Kärkkäinen in PR7404. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7791080151
commit
1f01109254
@ -888,14 +888,19 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
|
||||
#else
|
||||
// Okay, looks like we have to do it all by our lonesome.
|
||||
static unsigned FCounter = 0;
|
||||
unsigned offset = path.size() + 1;
|
||||
while ( FCounter < 999999 && exists()) {
|
||||
sprintf(FNBuffer+offset,"%06u",++FCounter);
|
||||
path = FNBuffer;
|
||||
}
|
||||
if (FCounter > 999999)
|
||||
// Try to initialize with unique value.
|
||||
if (FCounter == 0) FCounter = ((unsigned)getpid() & 0xFFFF) << 8;
|
||||
char* pos = strstr(FNBuffer, "XXXXXX");
|
||||
do {
|
||||
if (++FCounter > 0xFFFFFF) {
|
||||
return MakeErrMsg(ErrMsg,
|
||||
path + ": can't make unique filename: too many files");
|
||||
}
|
||||
sprintf(pos, "%06X", FCounter);
|
||||
path = FNBuffer;
|
||||
} while (exists());
|
||||
// POSSIBLE SECURITY BUG: An attacker can easily guess the name and exploit
|
||||
// LLVM.
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user