Skip to content

Commit d1e956f

Browse files
committed
[Backtracing] Add check for theoretical environment overflow issue.
Pretty sure this can't ever trigger because of operating system limits on the size of environment strings, but since overflow tests are cheap, there seems no reason not to add one. rdar://160307933
1 parent 8c5acc0 commit d1e956f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

stdlib/public/runtime/Backtrace.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,11 @@ _swift_backtraceSetupEnvironment()
902902

903903
size_t nameLen = std::strlen(name);
904904
size_t valueLen = std::strlen(value);
905-
size_t totalLen = nameLen + 1 + valueLen + 1;
905+
size_t totalLen;
906+
907+
if (__builtin_add_overflow(nameLen + 1, valueLen + 1, &totalLen)) {
908+
break;
909+
}
906910

907911
if (remaining > totalLen) {
908912
std::memcpy(penv, name, nameLen);

0 commit comments

Comments
 (0)