| Differences between
and this patch
- a/Source/JavaScriptCore/ChangeLog +24 lines
Lines 1-3 a/Source/JavaScriptCore/ChangeLog_sec1
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
3
        Do not use strerror()
4
        https://bugs.webkit.org/show_bug.cgi?id=231913
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * API/JSScript.mm:
9
        (-[JSScript writeCache:]):
10
        * API/tests/testapi.mm:
11
        (resolvePathToScripts):
12
        * jsc.cpp:
13
        * runtime/BytecodeCacheError.cpp:
14
        (JSC::BytecodeCacheError::StandardError::message const):
15
        * tools/FunctionAllowlist.cpp:
16
        (JSC::FunctionAllowlist::FunctionAllowlist):
17
        * tools/FunctionOverrides.cpp:
18
        (JSC::FunctionOverrides::parseOverridesInFile):
19
        * wasm/WasmMemory.cpp:
20
        (JSC::Wasm::MemoryHandle::~MemoryHandle):
21
        (JSC::Wasm::Memory::tryCreate):
22
        (JSC::Wasm::Memory::growShared):
23
        (JSC::Wasm::Memory::grow):
24
1
2021-10-18  Phillip Mates  <pmates@igalia.com>
25
2021-10-18  Phillip Mates  <pmates@igalia.com>
2
26
3
        shadow realms implementation
27
        shadow realms implementation
- a/Source/WTF/ChangeLog +20 lines
Lines 1-3 a/Source/WTF/ChangeLog_sec1
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
3
        Do not use strerror()
4
        https://bugs.webkit.org/show_bug.cgi?id=231913
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Add a new safeStrerror function that we can use without threadsafety worries.
9
10
        * wtf/CMakeLists.txt:
11
        * wtf/SafeStrerror.cpp: Added.
12
        (WTF::safeStrerror):
13
        * wtf/SafeStrerror.h: Added.
14
        * wtf/playstation/FileSystemPlayStation.cpp:
15
        (WTF::FileSystemImpl::deleteFile):
16
        * wtf/posix/FileSystemPOSIX.cpp:
17
        (WTF::FileSystemImpl::deleteFile):
18
        * wtf/threads/Signals.cpp:
19
        (WTF::jscSignalHandler):
20
1
2021-10-19  Cameron McCormack  <heycam@apple.com>
21
2021-10-19  Cameron McCormack  <heycam@apple.com>
2
22
3
        Ensure CanvasRenderingContext2D.drawImage(video) uses the right color space
23
        Ensure CanvasRenderingContext2D.drawImage(video) uses the right color space
- a/Source/WebKit/ChangeLog +18 lines
Lines 1-3 a/Source/WebKit/ChangeLog_sec1
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
3
        Do not use strerror()
4
        https://bugs.webkit.org/show_bug.cgi?id=231913
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * Platform/IPC/unix/ConnectionUnix.cpp:
9
        (IPC::Connection::readyReadHandler):
10
        * Platform/unix/SharedMemoryUnix.cpp:
11
        (WebKit::SharedMemory::allocate):
12
        * Shared/mac/AuxiliaryProcessMac.mm:
13
        (WebKit::setAndSerializeSandboxParameters):
14
        (WebKit::sandboxDataVaultParentDirectory):
15
        (WebKit::ensureSandboxCacheDirectory):
16
        (WebKit::tryApplyCachedSandbox):
17
        (WebKit::applySandbox):
18
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
19
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
20
3
        Update seccomp filters with latest changes from flatpak
21
        Update seccomp filters with latest changes from flatpak
- a/Source/bmalloc/ChangeLog +10 lines
Lines 1-3 a/Source/bmalloc/ChangeLog_sec1
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
3
        Do not use strerror()
4
        https://bugs.webkit.org/show_bug.cgi?id=231913
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * libpas/src/libpas/pas_page_malloc.c:
9
        (pas_page_malloc_commit):
10
1
2021-10-16  Commit Queue  <commit-queue@webkit.org>
11
2021-10-16  Commit Queue  <commit-queue@webkit.org>
2
12
3
        Unreviewed, reverting r284305.
13
        Unreviewed, reverting r284305.
- a/Source/JavaScriptCore/API/JSScript.mm -2 / +3 lines
Lines 40-45 a/Source/JavaScriptCore/API/JSScript.mm_sec1
40
#import <sys/stat.h>
40
#import <sys/stat.h>
41
#import <wtf/FileSystem.h>
41
#import <wtf/FileSystem.h>
42
#import <wtf/SHA1.h>
42
#import <wtf/SHA1.h>
43
#import <wtf/SafeStrerror.h>
43
#import <wtf/Scope.h>
44
#import <wtf/Scope.h>
44
#import <wtf/WeakObjCPtr.h>
45
#import <wtf/WeakObjCPtr.h>
45
#import <wtf/spi/darwin/DataVaultSPI.h>
46
#import <wtf/spi/darwin/DataVaultSPI.h>
Lines 304-310 - (BOOL)writeCache:(String&)error a/Source/JavaScriptCore/API/JSScript.mm_sec2
304
    const char* tempFileName = [cachePathString stringByAppendingString:@".tmp"].UTF8String;
305
    const char* tempFileName = [cachePathString stringByAppendingString:@".tmp"].UTF8String;
305
    int fd = open(cacheFileName, O_CREAT | O_WRONLY | O_EXLOCK | O_NONBLOCK, 0600);
306
    int fd = open(cacheFileName, O_CREAT | O_WRONLY | O_EXLOCK | O_NONBLOCK, 0600);
306
    if (fd == -1) {
307
    if (fd == -1) {
307
        error = makeString("Could not open or lock the bytecode cache file. It's likely another VM or process is already using it. Error: ", strerror(errno));
308
        error = makeString("Could not open or lock the bytecode cache file. It's likely another VM or process is already using it. Error: ", safeStrerror(errno));
308
        return NO;
309
        return NO;
309
    }
310
    }
310
311
Lines 314-320 - (BOOL)writeCache:(String&)error a/Source/JavaScriptCore/API/JSScript.mm_sec3
314
315
315
    int tempFD = open(tempFileName, O_CREAT | O_RDWR | O_EXLOCK | O_NONBLOCK, 0600);
316
    int tempFD = open(tempFileName, O_CREAT | O_RDWR | O_EXLOCK | O_NONBLOCK, 0600);
316
    if (tempFD == -1) {
317
    if (tempFD == -1) {
317
        error = makeString("Could not open or lock the bytecode cache temp file. Error: ", strerror(errno));
318
        error = makeString("Could not open or lock the bytecode cache temp file. Error: ", safeStrerror(errno));
318
        return NO;
319
        return NO;
319
    }
320
    }
320
321
- a/Source/JavaScriptCore/API/tests/testapi.mm -1 / +2 lines
Lines 39-44 a/Source/JavaScriptCore/API/tests/testapi.mm_sec1
39
#import "JSWrapperMapTests.h"
39
#import "JSWrapperMapTests.h"
40
#import "Regress141275.h"
40
#import "Regress141275.h"
41
#import "Regress141809.h"
41
#import "Regress141809.h"
42
#import <wtf/SafeStrerror.h>
42
#import <wtf/spi/darwin/DataVaultSPI.h>
43
#import <wtf/spi/darwin/DataVaultSPI.h>
43
44
44
45
Lines 2448-2454 static NSURL *resolvePathToScripts() a/Source/JavaScriptCore/API/tests/testapi.mm_sec2
2448
        const size_t maxLength = 10000;
2449
        const size_t maxLength = 10000;
2449
        char cwd[maxLength];
2450
        char cwd[maxLength];
2450
        if (!getcwd(cwd, maxLength)) {
2451
        if (!getcwd(cwd, maxLength)) {
2451
            NSLog(@"getcwd errored with code: %s", strerror(errno));
2452
            NSLog(@"getcwd errored with code: %s", safeStrerror(errno));
2452
            exit(1);
2453
            exit(1);
2453
        }
2454
        }
2454
        NSURL *cwdURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%s", cwd]];
2455
        NSURL *cwdURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%s", cwd]];
- a/Source/JavaScriptCore/jsc.cpp -1 / +2 lines
Lines 88-93 a/Source/JavaScriptCore/jsc.cpp_sec1
88
#include <wtf/MainThread.h>
88
#include <wtf/MainThread.h>
89
#include <wtf/MemoryPressureHandler.h>
89
#include <wtf/MemoryPressureHandler.h>
90
#include <wtf/MonotonicTime.h>
90
#include <wtf/MonotonicTime.h>
91
#include <wtf/SafeStrerror.h>
91
#include <wtf/Scope.h>
92
#include <wtf/Scope.h>
92
#include <wtf/StringPrintStream.h>
93
#include <wtf/StringPrintStream.h>
93
#include <wtf/URL.h>
94
#include <wtf/URL.h>
Lines 1819-1825 JSC_DEFINE_HOST_FUNCTION(functionOpenFile, (JSGlobalObject* globalObject, CallFr a/Source/JavaScriptCore/jsc.cpp_sec2
1819
1820
1820
    FILE* descriptor = fopen(filePath.fileSystemPath().ascii().data(), "r");
1821
    FILE* descriptor = fopen(filePath.fileSystemPath().ascii().data(), "r");
1821
    if (!descriptor)
1822
    if (!descriptor)
1822
        return throwVMException(globalObject, scope, createURIError(globalObject, makeString("Could not open file at "_s, filePath.string(), " fopen had error: "_s, strerror(errno))));
1823
        return throwVMException(globalObject, scope, createURIError(globalObject, makeString("Could not open file at "_s, filePath.string(), " fopen had error: "_s, safeStrerror(errno))));
1823
1824
1824
    RELEASE_AND_RETURN(scope, JSValue::encode(JSFileDescriptor::create(vm, globalObject, WTFMove(descriptor))));
1825
    RELEASE_AND_RETURN(scope, JSValue::encode(JSFileDescriptor::create(vm, globalObject, WTFMove(descriptor))));
1825
}
1826
}
- a/Source/JavaScriptCore/runtime/BytecodeCacheError.cpp -1 / +3 lines
Lines 26-31 a/Source/JavaScriptCore/runtime/BytecodeCacheError.cpp_sec1
26
#include "config.h"
26
#include "config.h"
27
#include "BytecodeCacheError.h"
27
#include "BytecodeCacheError.h"
28
28
29
#include <wtf/SafeStrerror.h>
30
29
namespace JSC {
31
namespace JSC {
30
32
31
bool BytecodeCacheError::StandardError::isValid() const
33
bool BytecodeCacheError::StandardError::isValid() const
Lines 35-41 bool BytecodeCacheError::StandardError::isValid() const a/Source/JavaScriptCore/runtime/BytecodeCacheError.cpp_sec2
35
37
36
String BytecodeCacheError::StandardError::message() const
38
String BytecodeCacheError::StandardError::message() const
37
{
39
{
38
    return strerror(m_errno);
40
    return safeStrerror(m_errno);
39
}
41
}
40
42
41
bool BytecodeCacheError::WriteError::isValid() const
43
bool BytecodeCacheError::WriteError::isValid() const
- a/Source/JavaScriptCore/tools/FunctionAllowlist.cpp -2 / +3 lines
Lines 31-36 a/Source/JavaScriptCore/tools/FunctionAllowlist.cpp_sec1
31
#include "CodeBlock.h"
31
#include "CodeBlock.h"
32
#include <stdio.h>
32
#include <stdio.h>
33
#include <string.h>
33
#include <string.h>
34
#include <wtf/SafeStrerror.h>
34
35
35
namespace JSC {
36
namespace JSC {
36
37
Lines 45-51 FunctionAllowlist::FunctionAllowlist(const char* filename) a/Source/JavaScriptCore/tools/FunctionAllowlist.cpp_sec2
45
            m_hasActiveAllowlist = true;
46
            m_hasActiveAllowlist = true;
46
            m_entries.add(filename);
47
            m_entries.add(filename);
47
        } else
48
        } else
48
            dataLogF("Failed to open file %s. Did you add the file-read-data entitlement to WebProcess.sb? Error code: %s\n", filename, strerror(errno));
49
            dataLogF("Failed to open file %s. Did you add the file-read-data entitlement to WebProcess.sb? Error code: %s\n", filename, safeStrerror(errno));
49
        return;
50
        return;
50
    }
51
    }
51
52
Lines 73-79 FunctionAllowlist::FunctionAllowlist(const char* filename) a/Source/JavaScriptCore/tools/FunctionAllowlist.cpp_sec3
73
74
74
    int result = fclose(f);
75
    int result = fclose(f);
75
    if (result)
76
    if (result)
76
        dataLogF("Failed to close file %s: %s\n", filename, strerror(errno));
77
        dataLogF("Failed to close file %s: %s\n", filename, safeStrerror(errno));
77
}
78
}
78
79
79
bool FunctionAllowlist::contains(CodeBlock* codeBlock) const
80
bool FunctionAllowlist::contains(CodeBlock* codeBlock) const
- a/Source/JavaScriptCore/tools/FunctionOverrides.cpp -1 / +2 lines
Lines 31-36 a/Source/JavaScriptCore/tools/FunctionOverrides.cpp_sec1
31
#include <string.h>
31
#include <string.h>
32
#include <wtf/DataLog.h>
32
#include <wtf/DataLog.h>
33
#include <wtf/NeverDestroyed.h>
33
#include <wtf/NeverDestroyed.h>
34
#include <wtf/SafeStrerror.h>
34
#include <wtf/text/CString.h>
35
#include <wtf/text/CString.h>
35
#include <wtf/text/StringBuilder.h>
36
#include <wtf/text/StringBuilder.h>
36
#include <wtf/text/StringHash.h>
37
#include <wtf/text/StringHash.h>
Lines 283-289 void FunctionOverrides::parseOverridesInFile(const char* fileName) a/Source/JavaScriptCore/tools/FunctionOverrides.cpp_sec2
283
    
284
    
284
    int result = fclose(file);
285
    int result = fclose(file);
285
    if (result)
286
    if (result)
286
        dataLogF("Failed to close file %s: %s\n", fileName, strerror(errno));
287
        dataLogF("Failed to close file %s: %s\n", fileName, safeStrerror(errno));
287
}
288
}
288
    
289
    
289
} // namespace JSC
290
} // namespace JSC
- a/Source/JavaScriptCore/wasm/WasmMemory.cpp -6 / +7 lines
Lines 37-42 a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec1
37
#include <wtf/Platform.h>
37
#include <wtf/Platform.h>
38
#include <wtf/PrintStream.h>
38
#include <wtf/PrintStream.h>
39
#include <wtf/RAMSize.h>
39
#include <wtf/RAMSize.h>
40
#include <wtf/SafeStrerror.h>
40
#include <wtf/StdSet.h>
41
#include <wtf/StdSet.h>
41
#include <wtf/Vector.h>
42
#include <wtf/Vector.h>
42
43
Lines 301-307 MemoryHandle::~MemoryHandle() a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec2
301
        switch (m_mode) {
302
        switch (m_mode) {
302
        case MemoryMode::Signaling:
303
        case MemoryMode::Signaling:
303
            if (mprotect(memory, Memory::fastMappedBytes(), PROT_READ | PROT_WRITE)) {
304
            if (mprotect(memory, Memory::fastMappedBytes(), PROT_READ | PROT_WRITE)) {
304
                dataLog("mprotect failed: ", strerror(errno), "\n");
305
                dataLog("mprotect failed: ", safeStrerror(errno), "\n");
305
                RELEASE_ASSERT_NOT_REACHED();
306
                RELEASE_ASSERT_NOT_REACHED();
306
            }
307
            }
307
            memoryManager().freeFastMemory(memory);
308
            memoryManager().freeFastMemory(memory);
Lines 313-319 MemoryHandle::~MemoryHandle() a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec3
313
                break;
314
                break;
314
            case MemorySharingMode::Shared: {
315
            case MemorySharingMode::Shared: {
315
                if (mprotect(memory, m_mappedCapacity, PROT_READ | PROT_WRITE)) {
316
                if (mprotect(memory, m_mappedCapacity, PROT_READ | PROT_WRITE)) {
316
                    dataLog("mprotect failed: ", strerror(errno), "\n");
317
                    dataLog("mprotect failed: ", safeStrerror(errno), "\n");
317
                    RELEASE_ASSERT_NOT_REACHED();
318
                    RELEASE_ASSERT_NOT_REACHED();
318
                }
319
                }
319
                memoryManager().freeGrowableBoundsCheckingMemory(memory, m_mappedCapacity);
320
                memoryManager().freeGrowableBoundsCheckingMemory(memory, m_mappedCapacity);
Lines 406-412 RefPtr<Memory> Memory::tryCreate(PageCount initial, PageCount maximum, MemorySha a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec4
406
    
407
    
407
    if (fastMemory) {
408
    if (fastMemory) {
408
        if (mprotect(fastMemory + initialBytes, Memory::fastMappedBytes() - initialBytes, PROT_NONE)) {
409
        if (mprotect(fastMemory + initialBytes, Memory::fastMappedBytes() - initialBytes, PROT_NONE)) {
409
            dataLog("mprotect failed: ", strerror(errno), "\n");
410
            dataLog("mprotect failed: ", safeStrerror(errno), "\n");
410
            RELEASE_ASSERT_NOT_REACHED();
411
            RELEASE_ASSERT_NOT_REACHED();
411
        }
412
        }
412
413
Lines 442-448 RefPtr<Memory> Memory::tryCreate(PageCount initial, PageCount maximum, MemorySha a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec5
442
        }
443
        }
443
444
444
        if (mprotect(slowMemory + initialBytes, maximumBytes - initialBytes, PROT_NONE)) {
445
        if (mprotect(slowMemory + initialBytes, maximumBytes - initialBytes, PROT_NONE)) {
445
            dataLog("mprotect failed: ", strerror(errno), "\n");
446
            dataLog("mprotect failed: ", safeStrerror(errno), "\n");
446
            RELEASE_ASSERT_NOT_REACHED();
447
            RELEASE_ASSERT_NOT_REACHED();
447
        }
448
        }
448
449
Lines 516-522 Expected<PageCount, Memory::GrowFailReason> Memory::growShared(PageCount delta) a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec6
516
517
517
        dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
518
        dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
518
        if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) {
519
        if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) {
519
            dataLog("mprotect failed: ", strerror(errno), "\n");
520
            dataLog("mprotect failed: ", safeStrerror(errno), "\n");
520
            RELEASE_ASSERT_NOT_REACHED();
521
            RELEASE_ASSERT_NOT_REACHED();
521
        }
522
        }
522
523
Lines 605-611 Expected<PageCount, Memory::GrowFailReason> Memory::grow(PageCount delta) a/Source/JavaScriptCore/wasm/WasmMemory.cpp_sec7
605
        
606
        
606
        dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
607
        dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
607
        if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) {
608
        if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) {
608
            dataLog("mprotect failed: ", strerror(errno), "\n");
609
            dataLog("mprotect failed: ", safeStrerror(errno), "\n");
609
            RELEASE_ASSERT_NOT_REACHED();
610
            RELEASE_ASSERT_NOT_REACHED();
610
        }
611
        }
611
612
- a/Source/WTF/WTF.xcodeproj/project.pbxproj +6 lines
Lines 73-78 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec1
73
		337B2D6A26546EB300DDFD3D /* LikelyDenseUnsignedIntegerSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 337B2D6826546EAA00DDFD3D /* LikelyDenseUnsignedIntegerSet.cpp */; };
73
		337B2D6A26546EB300DDFD3D /* LikelyDenseUnsignedIntegerSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 337B2D6826546EAA00DDFD3D /* LikelyDenseUnsignedIntegerSet.cpp */; };
74
		4427C5AA21F6D6C300A612A4 /* ASCIICType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4427C5A921F6D6C300A612A4 /* ASCIICType.cpp */; };
74
		4427C5AA21F6D6C300A612A4 /* ASCIICType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4427C5A921F6D6C300A612A4 /* ASCIICType.cpp */; };
75
		46BEB6EB22FFE24900269867 /* RefCounted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46BEB6E922FFDDD500269867 /* RefCounted.cpp */; };
75
		46BEB6EB22FFE24900269867 /* RefCounted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46BEB6E922FFDDD500269867 /* RefCounted.cpp */; };
76
		46E93049271F1205005BA6E5 /* SafeStrerror.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E43647271F10AA00C88C90 /* SafeStrerror.cpp */; };
76
		50DE35F5215BB01500B979C7 /* ExternalStringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */; };
77
		50DE35F5215BB01500B979C7 /* ExternalStringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */; };
77
		515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */; };
78
		515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */; };
78
		517F82D71FD22F3000DA3DEA /* CrossThreadTaskHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517F82D51FD22F2F00DA3DEA /* CrossThreadTaskHandler.cpp */; };
79
		517F82D71FD22F3000DA3DEA /* CrossThreadTaskHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517F82D51FD22F2F00DA3DEA /* CrossThreadTaskHandler.cpp */; };
Lines 397-402 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec2
397
		46209A27266D543A007F8F4A /* CancellableTask.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CancellableTask.h; sourceTree = "<group>"; };
398
		46209A27266D543A007F8F4A /* CancellableTask.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CancellableTask.h; sourceTree = "<group>"; };
398
		46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompletionHandler.h; sourceTree = "<group>"; };
399
		46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompletionHandler.h; sourceTree = "<group>"; };
399
		46BEB6E922FFDDD500269867 /* RefCounted.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounted.cpp; sourceTree = "<group>"; };
400
		46BEB6E922FFDDD500269867 /* RefCounted.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounted.cpp; sourceTree = "<group>"; };
401
		46E43646271F10AA00C88C90 /* SafeStrerror.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SafeStrerror.h; sourceTree = "<group>"; };
402
		46E43647271F10AA00C88C90 /* SafeStrerror.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SafeStrerror.cpp; sourceTree = "<group>"; };
400
		50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExternalStringImpl.cpp; sourceTree = "<group>"; };
403
		50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExternalStringImpl.cpp; sourceTree = "<group>"; };
401
		50DE35F4215BB01500B979C7 /* ExternalStringImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExternalStringImpl.h; sourceTree = "<group>"; };
404
		50DE35F4215BB01500B979C7 /* ExternalStringImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExternalStringImpl.h; sourceTree = "<group>"; };
402
		513E170A1CD7D5BF00E3650B /* LoggingAccumulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggingAccumulator.h; sourceTree = "<group>"; };
405
		513E170A1CD7D5BF00E3650B /* LoggingAccumulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggingAccumulator.h; sourceTree = "<group>"; };
Lines 1277-1282 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec3
1277
				E31CF0A5261058580036E673 /* RobinHoodHashTable.h */,
1280
				E31CF0A5261058580036E673 /* RobinHoodHashTable.h */,
1278
				2CDED0F118115C85004DBA70 /* RunLoop.cpp */,
1281
				2CDED0F118115C85004DBA70 /* RunLoop.cpp */,
1279
				2CDED0F218115C85004DBA70 /* RunLoop.h */,
1282
				2CDED0F218115C85004DBA70 /* RunLoop.h */,
1283
				46E43647271F10AA00C88C90 /* SafeStrerror.cpp */,
1284
				46E43646271F10AA00C88C90 /* SafeStrerror.h */,
1280
				14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */,
1285
				14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */,
1281
				1469419416EAAFF80024E146 /* SchedulePair.h */,
1286
				1469419416EAAFF80024E146 /* SchedulePair.h */,
1282
				1A3524AA1D63A2FF0031729B /* Scope.h */,
1287
				1A3524AA1D63A2FF0031729B /* Scope.h */,
Lines 1821-1826 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec4
1821
				2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */,
1826
				2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */,
1822
				2CDED0EF18115C38004DBA70 /* RunLoopCF.cpp in Sources */,
1827
				2CDED0EF18115C38004DBA70 /* RunLoopCF.cpp in Sources */,
1823
				1CA85CA9241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp in Sources */,
1828
				1CA85CA9241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp in Sources */,
1829
				46E93049271F1205005BA6E5 /* SafeStrerror.cpp in Sources */,
1824
				A3EE5C3D21FFAC7D00FABD61 /* SchedulePairCF.cpp in Sources */,
1830
				A3EE5C3D21FFAC7D00FABD61 /* SchedulePairCF.cpp in Sources */,
1825
				A3EE5C4021FFACA200FABD61 /* SchedulePairMac.mm in Sources */,
1831
				A3EE5C4021FFACA200FABD61 /* SchedulePairMac.mm in Sources */,
1826
				0F66B28E1DC97BAB004A1D3F /* Seconds.cpp in Sources */,
1832
				0F66B28E1DC97BAB004A1D3F /* Seconds.cpp in Sources */,
- a/Source/WTF/wtf/CMakeLists.txt +2 lines
Lines 230-235 set(WTF_PUBLIC_HEADERS a/Source/WTF/wtf/CMakeLists.txt_sec1
230
    RobinHoodHashTable.h
230
    RobinHoodHashTable.h
231
    RunLoop.h
231
    RunLoop.h
232
    SHA1.h
232
    SHA1.h
233
    SafeStrerror.h
233
    SaturatedArithmetic.h
234
    SaturatedArithmetic.h
234
    SchedulePair.h
235
    SchedulePair.h
235
    Scope.h
236
    Scope.h
Lines 459-464 set(WTF_SOURCES a/Source/WTF/wtf/CMakeLists.txt_sec2
459
    RefCountedLeakCounter.cpp
460
    RefCountedLeakCounter.cpp
460
    RunLoop.cpp
461
    RunLoop.cpp
461
    SHA1.cpp
462
    SHA1.cpp
463
    SafeStrerror.cpp
462
    Seconds.cpp
464
    Seconds.cpp
463
    SegmentedVector.cpp
465
    SegmentedVector.cpp
464
    SixCharacterHash.cpp
466
    SixCharacterHash.cpp
- a/Source/WTF/wtf/SafeStrerror.cpp +85 lines
Line 0 a/Source/WTF/wtf/SafeStrerror.cpp_sec1
1
/* 
2
 * Copyright (C) 2021 Red Hat Inc.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include "config.h"
19
#include <wtf/SafeStrerror.h>
20
21
#include <cstring>
22
#include <type_traits>
23
#include <wtf/HashMap.h>
24
#include <wtf/Locker.h>
25
#include <wtf/NeverDestroyed.h>
26
#include <wtf/Platform.h>
27
#include <wtf/text/WTFString.h>
28
29
#if USE(GLIB)
30
#include <glib.h>
31
#endif
32
33
namespace WTF {
34
35
#if !USE(GLIB) || !OS(WINDOWS)
36
static char* strErrorAdaptor(int errnum, char* buffer, size_t bufferLength)
37
{
38
    // GNU strerror_r and POSIX strerror_r are incompatible, and my attempts to use feature test
39
    // macros to force use of POSIX strerror_r all failed due to bugs in the libstdc++ headers.
40
    auto ret = strerror_r(errnum, buffer, bufferLength);
41
    if constexpr (std::is_same<decltype(ret), char*>::value) {
42
        // GNU strerror_r
43
        return reinterpret_cast<char*>(ret);
44
    }
45
    // POSIX strerror_r
46
    if (ret)
47
        *buffer = '\0';
48
    return buffer;
49
}
50
#endif
51
52
const char* safeStrerror(int errnum)
53
{
54
#if USE(GLIB)
55
    // Might as well reuse GLib's existing map of error messages instead of keeping a second one.
56
    return g_strerror(errnum);
57
#else
58
    // This is implementation is based on GLib's g_strerror (from gstrfuncs.c, LGPLv2.1+).
59
    static Lock lock;
60
    static NeverDestroyed<HashMap<int, CString>> errorsMap WTF_GUARDED_BY_LOCK(lock);
61
62
    Locker locker { lock };
63
    auto result = errorsMap->get(errnum);
64
    if (!result.isNull())
65
        return result.data();
66
67
    char buffer[2048];
68
    char* message = nullptr;
69
#if OS(WINDOWS)
70
    strerror_s(buffer, sizeof(buffer), errnum);
71
    message = buffer;
72
#else
73
    message = strErrorAdaptor(errnum, buffer, sizeof(buffer));
74
#endif // OS(WINDOWS)
75
76
    errorsMap->add(errnum, message);
77
78
    // Ensure we return a pointer to the message we own in errorsMap, whose lifetime we guarantee.
79
    result = errorsMap->get(errnum);
80
    ASSERT(!result.isNull());
81
    return result.data();
82
#endif // USE(GLIB)
83
}
84
85
} // namespace WTF
- a/Source/WTF/wtf/SafeStrerror.h +40 lines
Line 0 a/Source/WTF/wtf/SafeStrerror.h_sec1
1
/* 
2
 * Copyright (C) 2021 Red Hat Inc.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#pragma once
19
20
#include <wtf/text/CString.h>
21
22
namespace WTF {
23
24
// This is strerror, except it is threadsafe. The problem with normal strerror is it returns a
25
// pointer to static storage, and it may actually modify that storage, so it can never be used in
26
// any multithreaded application, or any library that may be linked to a multithreaded application.
27
// (Why does it modify its storage? So that it can append the error number to the error string, as
28
// in "Unknown error n.") The standard alternatives are strerror_s and strerror_r, but both have
29
// problems. strerror_s is specified by C11, but not by C++ (as of C++20), and it is optional so
30
// glibc decided to ignore it. We can only rely on it to exist on Windows. Then strerror_r is even
31
// worse. First, it doesn't exist at all on Windows. Second, the GNU version is incompatible with
32
// the POSIX version, and it is impossible to use correctly unless you know which version you have.
33
// Both strerror_s and strerror_r are cumbersome because they force you to allocate the buffer for
34
// the result manually. It's all such a mess that we should deal with the complexity here rather
35
// than elsewhere in WebKit.
36
WTF_EXPORT_PRIVATE const char* safeStrerror(int errnum);
37
38
}
39
40
using WTF::safeStrerror;
- a/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp -1 / +2 lines
Lines 37-42 a/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp_sec1
37
#include <sys/statvfs.h>
37
#include <sys/statvfs.h>
38
#include <sys/types.h>
38
#include <sys/types.h>
39
#include <unistd.h>
39
#include <unistd.h>
40
#include <wtf/SafeStrerror.h>
40
#include <wtf/text/StringBuilder.h>
41
#include <wtf/text/StringBuilder.h>
41
42
42
namespace WTF {
43
namespace WTF {
Lines 88-94 bool deleteFile(const String& path) a/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp_sec2
88
    // unlink(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
89
    // unlink(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
89
    bool unlinked = !unlink(fsRep.data());
90
    bool unlinked = !unlink(fsRep.data());
90
    if (!unlinked && errno != ENOENT)
91
    if (!unlinked && errno != ENOENT)
91
        LOG_ERROR("File failed to delete. Error message: %s", strerror(errno));
92
        LOG_ERROR("File failed to delete. Error message: %s", safeStrerror(errno));
92
93
93
    return unlinked;
94
    return unlinked;
94
}
95
}
- a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp -1 / +2 lines
Lines 40-45 a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp_sec1
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <unistd.h>
41
#include <unistd.h>
42
#include <wtf/EnumTraits.h>
42
#include <wtf/EnumTraits.h>
43
#include <wtf/SafeStrerror.h>
43
#include <wtf/text/CString.h>
44
#include <wtf/text/CString.h>
44
#include <wtf/text/StringBuilder.h>
45
#include <wtf/text/StringBuilder.h>
45
#include <wtf/text/WTFString.h>
46
#include <wtf/text/WTFString.h>
Lines 261-267 bool deleteFile(const String& path) a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp_sec2
261
    // unlink(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
262
    // unlink(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
262
    bool unlinked = !unlink(fileSystemRepresentation(path).data());
263
    bool unlinked = !unlink(fileSystemRepresentation(path).data());
263
    if (!unlinked && errno != ENOENT)
264
    if (!unlinked && errno != ENOENT)
264
        LOG_ERROR("File failed to delete. Error message: %s", strerror(errno));
265
        LOG_ERROR("File failed to delete. Error message: %s", safeStrerror(errno));
265
266
266
    return unlinked;
267
    return unlinked;
267
}
268
}
- a/Source/WTF/wtf/threads/Signals.cpp -1 / +2 lines
Lines 53-58 extern "C" { a/Source/WTF/wtf/threads/Signals.cpp_sec1
53
#include <wtf/MathExtras.h>
53
#include <wtf/MathExtras.h>
54
#include <wtf/NeverDestroyed.h>
54
#include <wtf/NeverDestroyed.h>
55
#include <wtf/PlatformRegisters.h>
55
#include <wtf/PlatformRegisters.h>
56
#include <wtf/SafeStrerror.h>
56
#include <wtf/ThreadGroup.h>
57
#include <wtf/ThreadGroup.h>
57
#include <wtf/Threading.h>
58
#include <wtf/Threading.h>
58
#include <wtf/WTFConfig.h>
59
#include <wtf/WTFConfig.h>
Lines 384-390 void jscSignalHandler(int sig, siginfo_t* info, void* ucontext) a/Source/WTF/wtf/threads/Signals.cpp_sec2
384
        sigfillset(&defaultAction.sa_mask);
385
        sigfillset(&defaultAction.sa_mask);
385
        defaultAction.sa_flags = 0;
386
        defaultAction.sa_flags = 0;
386
        auto result = sigaction(sig, &defaultAction, nullptr);
387
        auto result = sigaction(sig, &defaultAction, nullptr);
387
        dataLogLnIf(result == -1, "Unable to restore the default handler while proccessing signal ", sig, " the process is probably deadlocked. (errno: ", strerror(errno), ")");
388
        dataLogLnIf(result == -1, "Unable to restore the default handler while proccessing signal ", sig, " the process is probably deadlocked. (errno: ", safeStrerror(errno), ")");
388
    };
389
    };
389
390
390
    // This shouldn't happen but we might as well be careful.
391
    // This shouldn't happen but we might as well be careful.
- a/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp -1 / +2 lines
Lines 37-42 a/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp_sec1
37
#include <fcntl.h>
37
#include <fcntl.h>
38
#include <poll.h>
38
#include <poll.h>
39
#include <wtf/Assertions.h>
39
#include <wtf/Assertions.h>
40
#include <wtf/SafeStrerror.h>
40
#include <wtf/StdLibExtras.h>
41
#include <wtf/StdLibExtras.h>
41
#include <wtf/UniStdExtras.h>
42
#include <wtf/UniStdExtras.h>
42
43
Lines 352-358 void Connection::readyReadHandler() a/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp_sec2
352
            }
353
            }
353
354
354
            if (m_isConnected) {
355
            if (m_isConnected) {
355
                WTFLogAlways("Error receiving IPC message on socket %d in process %d: %s", m_socketDescriptor, getpid(), strerror(errno));
356
                WTFLogAlways("Error receiving IPC message on socket %d in process %d: %s", m_socketDescriptor, getpid(), safeStrerror(errno));
356
                connectionDidClose();
357
                connectionDidClose();
357
            }
358
            }
358
            return;
359
            return;
- a/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp -1 / +2 lines
Lines 41-46 a/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp_sec1
41
#include <unistd.h>
41
#include <unistd.h>
42
#include <wtf/Assertions.h>
42
#include <wtf/Assertions.h>
43
#include <wtf/RandomNumber.h>
43
#include <wtf/RandomNumber.h>
44
#include <wtf/SafeStrerror.h>
44
#include <wtf/UniStdExtras.h>
45
#include <wtf/UniStdExtras.h>
45
#include <wtf/text/CString.h>
46
#include <wtf/text/CString.h>
46
#include <wtf/text/WTFString.h>
47
#include <wtf/text/WTFString.h>
Lines 165-171 RefPtr<SharedMemory> SharedMemory::allocate(size_t size) a/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp_sec2
165
{
166
{
166
    int fileDescriptor = createSharedMemory();
167
    int fileDescriptor = createSharedMemory();
167
    if (fileDescriptor == -1) {
168
    if (fileDescriptor == -1) {
168
        WTFLogAlways("Failed to create shared memory: %s", strerror(errno));
169
        WTFLogAlways("Failed to create shared memory: %s", safeStrerror(errno));
169
        return nullptr;
170
        return nullptr;
170
    }
171
    }
171
172
- a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm -6 / +7 lines
Lines 51-56 a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec1
51
#import <wtf/DataLog.h>
51
#import <wtf/DataLog.h>
52
#import <wtf/FileSystem.h>
52
#import <wtf/FileSystem.h>
53
#import <wtf/RandomNumber.h>
53
#import <wtf/RandomNumber.h>
54
#import <wtf/SafeStrerror.h>
54
#import <wtf/Scope.h>
55
#import <wtf/Scope.h>
55
#import <wtf/SoftLinking.h>
56
#import <wtf/SoftLinking.h>
56
#import <wtf/SystemTracing.h>
57
#import <wtf/SystemTracing.h>
Lines 251-257 static std::optional<CString> setAndSerializeSandboxParameters(const SandboxInit a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec2
251
        const char* name = initializationParameters.name(i);
252
        const char* name = initializationParameters.name(i);
252
        const char* value = initializationParameters.value(i);
253
        const char* value = initializationParameters.value(i);
253
        if (sandbox_set_param(sandboxParameters.get(), name, value)) {
254
        if (sandbox_set_param(sandboxParameters.get(), name, value)) {
254
            WTFLogAlways("%s: Could not set sandbox parameter: %s\n", getprogname(), strerror(errno));
255
            WTFLogAlways("%s: Could not set sandbox parameter: %s\n", getprogname(), safeStrerror(errno));
255
            CRASH();
256
            CRASH();
256
        }
257
        }
257
        builder.append(name, ':', value, ':');
258
        builder.append(name, ':', value, ':');
Lines 271-283 static String sandboxDataVaultParentDirectory() a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec3
271
    char temp[PATH_MAX];
272
    char temp[PATH_MAX];
272
    size_t length = confstr(_CS_DARWIN_USER_CACHE_DIR, temp, sizeof(temp));
273
    size_t length = confstr(_CS_DARWIN_USER_CACHE_DIR, temp, sizeof(temp));
273
    if (!length) {
274
    if (!length) {
274
        WTFLogAlways("%s: Could not retrieve user temporary directory path: %s\n", getprogname(), strerror(errno));
275
        WTFLogAlways("%s: Could not retrieve user temporary directory path: %s\n", getprogname(), safeStrerror(errno));
275
        exit(EX_NOPERM);
276
        exit(EX_NOPERM);
276
    }
277
    }
277
    RELEASE_ASSERT(length <= sizeof(temp));
278
    RELEASE_ASSERT(length <= sizeof(temp));
278
    char resolvedPath[PATH_MAX];
279
    char resolvedPath[PATH_MAX];
279
    if (!realpath(temp, resolvedPath)) {
280
    if (!realpath(temp, resolvedPath)) {
280
        WTFLogAlways("%s: Could not canonicalize user temporary directory path: %s\n", getprogname(), strerror(errno));
281
        WTFLogAlways("%s: Could not canonicalize user temporary directory path: %s\n", getprogname(), safeStrerror(errno));
281
        exit(EX_NOPERM);
282
        exit(EX_NOPERM);
282
    }
283
    }
283
    return resolvedPath;
284
    return resolvedPath;
Lines 373-379 static bool ensureSandboxCacheDirectory(const SandboxInfo& info) a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec4
373
        if (!makeDataVault())
374
        if (!makeDataVault())
374
            return false;
375
            return false;
375
    } else {
376
    } else {
376
        WTFLogAlways("%s: Sandbox directory couldn't be created: ", getprogname(), strerror(errno));
377
        WTFLogAlways("%s: Sandbox directory couldn't be created: ", getprogname(), safeStrerror(errno));
377
        return false;
378
        return false;
378
    }
379
    }
379
#else
380
#else
Lines 521-527 static bool tryApplyCachedSandbox(const SandboxInfo& info) a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec5
521
    setNotifyOptions();
522
    setNotifyOptions();
522
523
523
    if (sandbox_apply(&profile)) {
524
    if (sandbox_apply(&profile)) {
524
        WTFLogAlways("%s: Could not apply cached sandbox: %s\n", getprogname(), strerror(errno));
525
        WTFLogAlways("%s: Could not apply cached sandbox: %s\n", getprogname(), safeStrerror(errno));
525
        return false;
526
        return false;
526
    }
527
    }
527
528
Lines 623-629 static bool applySandbox(const AuxiliaryProcessInitializationParameters& paramet a/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm_sec6
623
    setNotifyOptions();
624
    setNotifyOptions();
624
    
625
    
625
    if (sandbox_apply(sandboxProfile.get())) {
626
    if (sandbox_apply(sandboxProfile.get())) {
626
        WTFLogAlways("%s: Could not apply compiled sandbox: %s\n", getprogname(), strerror(errno));
627
        WTFLogAlways("%s: Could not apply compiled sandbox: %s\n", getprogname(), safeStrerror(errno));
627
        CRASH();
628
        CRASH();
628
    }
629
    }
629
630
- a/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c -1 / +6 lines
Lines 40-45 a/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c_sec1
40
#include <stdio.h>
40
#include <stdio.h>
41
#include <string.h>
41
#include <string.h>
42
#include <sys/mman.h>
42
#include <sys/mman.h>
43
#include <type_traits>
43
#include <unistd.h>
44
#include <unistd.h>
44
45
45
size_t pas_page_malloc_num_allocated_bytes;
46
size_t pas_page_malloc_num_allocated_bytes;
Lines 176-182 void pas_page_malloc_commit(void* ptr, size_t size) a/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c_sec2
176
    if (pas_page_malloc_mprotect_decommitted) {
177
    if (pas_page_malloc_mprotect_decommitted) {
177
        result = mprotect((void*)base_as_int, end_as_int - base_as_int, PROT_READ | PROT_WRITE);
178
        result = mprotect((void*)base_as_int, end_as_int - base_as_int, PROT_READ | PROT_WRITE);
178
        if (result) {
179
        if (result) {
179
            pas_log("Could not mprotect on commit: %s\n", strerror(errno));
180
            char buffer[2048];
181
            auto ret = strerror_r(errno, buffer, sizeof(buffer));
182
            // If you hit this when porting PAS to Linux, then see WTF's SafeStrerror.cpp.
183
            static_assert(std::is_same<decltype(ret), int>::value, "This code expects POSIX strerror_r, not GNU strerror_r");
184
            pas_log("Could not mprotect on commit: %s\n", buffer);
180
            PAS_ASSERT(!result);
185
            PAS_ASSERT(!result);
181
        }
186
        }
182
    }
187
    }
- a/Tools/ChangeLog +11 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2021-10-19  Michael Catanzaro  <mcatanzaro@gnome.org>
2
3
        Do not use strerror()
4
        https://bugs.webkit.org/show_bug.cgi?id=231913
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * TestWebKitAPI/CMakeLists.txt:
9
        * TestWebKitAPI/Tests/WTF/SafeStrerror.cpp: Added.
10
        (TestWebKitAPI::TEST):
11
1
2021-10-18  Commit Queue  <commit-queue@webkit.org>
12
2021-10-18  Commit Queue  <commit-queue@webkit.org>
2
13
3
        Unreviewed, reverting r284413.
14
        Unreviewed, reverting r284413.
- a/Tools/TestWebKitAPI/CMakeLists.txt +1 lines
Lines 82-87 set(TestWTF_SOURCES a/Tools/TestWebKitAPI/CMakeLists.txt_sec1
82
    Tests/WTF/RobinHoodHashSet.cpp
82
    Tests/WTF/RobinHoodHashSet.cpp
83
    Tests/WTF/RunLoop.cpp
83
    Tests/WTF/RunLoop.cpp
84
    Tests/WTF/SHA1.cpp
84
    Tests/WTF/SHA1.cpp
85
    Tests/WTF/SafeStrerror.cpp
85
    Tests/WTF/SaturatedArithmeticOperations.cpp
86
    Tests/WTF/SaturatedArithmeticOperations.cpp
86
    Tests/WTF/Scope.cpp
87
    Tests/WTF/Scope.cpp
87
    Tests/WTF/ScopedLambda.cpp
88
    Tests/WTF/ScopedLambda.cpp
- a/Tools/TestWebKitAPI/Tests/WTF/SafeStrerror.cpp +67 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WTF/SafeStrerror.cpp_sec1
1
/*
2
 * Copyright (C) 2021 Red Hat Inc.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 *
8
 * 1.  Redistributions of source code must retain the above copyright
9
 *     notice, this list of conditions and the following disclaimer. 
10
 * 2.  Redistributions in binary form must reproduce the above copyright
11
 *     notice, this list of conditions and the following disclaimer in the
12
 *     documentation and/or other materials provided with the distribution. 
13
 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
14
 *     its contributors may be used to endorse or promote products derived
15
 *     from this software without specific prior written permission. 
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
29
#include "config.h"
30
#include <wtf/SafeStrerror.h>
31
32
#include <cstring>
33
34
namespace TestWebKitAPI {
35
36
TEST(WTF_SafeStrerror, StringsAreEqual)
37
{
38
    for (int i = 0; i < 1000; i++) {
39
        // Actual text of errors should be identical.
40
        EXPECT_STREQ(strerror(i), safeStrerror(i));
41
    }
42
}
43
44
TEST(WTF_SafeStrerror, PointersAreNotEqual)
45
{
46
    // Since strerror() generally returns pointers that are not safe to use in multithreaded
47
    // programs, it would be nice to show that safeStrerror() returns different pointers.
48
    // Accordingly, I was tempted to loop over a bunch of different error codes here and verify that
49
    // the pointers returned by the two functions are not the same.
50
    //
51
    // But if we are using GLib, then safeStrerror() will return a result provided by g_strerror(),
52
    // which in turn returns a result provided by strerror_r() (if available). The glibc (GNU)
53
    // version of strerror_r() is weird in that it will usually return a pointer to the same static
54
    // memory that strerror() returns, but -- crucially -- it will only do so when it is guaranteed
55
    // that glibc will never modify that pointer. So when using GLib and glibc, it's actually OK for
56
    // these functions to return matching pointer values. However, if we pass an invalid error code,
57
    // then glibc will modify the returned string in order to add the invalid error code directly
58
    // into the string. In this case, strerror_r() will make a copy rather than return the same
59
    // static string that would be returned by errno.
60
    //
61
    // It's questionable whether this test is truly valuable, since it relies on so many
62
    // implementation details, but it's nice to show that safeStrerror() is doing *something*
63
    // differently than normal strerror(), even if we have to rely on this edge case to do so.
64
    EXPECT_NE(strerror(424242), safeStrerror(424242));
65
}
66
67
} // namespace TestWebKitAPI

Return to Bug 231913