Bug 187270 - [Cocoa] Disable vnode guard related simulated crashes for WKTR / DRT and WebSQL
Summary: [Cocoa] Disable vnode guard related simulated crashes for WKTR / DRT and WebSQL
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-07-02 14:39 PDT by Chris Dumez
Modified: 2020-12-22 16:09 PST (History)
7 users (show)

See Also:


Attachments
Patch (12.22 KB, patch)
2018-07-02 16:58 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.32 KB, patch)
2018-07-02 17:01 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.38 KB, patch)
2018-07-03 10:50 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.34 KB, patch)
2018-07-03 14:19 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2018-07-02 14:39:04 PDT
Disable vnode guard related simulated crashes for WKTR / DRT and WebSQL.
Comment 1 Chris Dumez 2018-07-02 14:39:21 PDT
<rdar://problem/40674034>
Comment 2 Chris Dumez 2018-07-02 16:58:38 PDT
Created attachment 344149 [details]
Patch
Comment 3 Chris Dumez 2018-07-02 17:01:09 PDT
Created attachment 344150 [details]
Patch
Comment 4 Alexey Proskuryakov 2018-07-03 02:19:49 PDT
Comment on attachment 344150 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=344150&action=review

> Source/WebCore/platform/posix/FileSystemPOSIX.cpp:454
> +String realPath(const String& filePath)
> +{
> +    CString fsRep = fileSystemRepresentation(filePath);
> +    char resolvedName[PATH_MAX];
> +    const char* result = realpath(fsRep.data(), resolvedName);
> +    return result ? String::fromUTF8(result) : filePath;
> +}

This doesn't look right to me. The idea behind fileSystemRepresentation() is that this is what one passes to POSIX functions, but here, the result is round-tripped through String::fromUTF8() and then utf8(). I don't really have an example of when this would fail, but this is conceptually incorrect and of course wasteful.
Comment 5 Chris Dumez 2018-07-03 08:48:24 PDT
Comment on attachment 344150 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=344150&action=review

>> Source/WebCore/platform/posix/FileSystemPOSIX.cpp:454
>> +}
> 
> This doesn't look right to me. The idea behind fileSystemRepresentation() is that this is what one passes to POSIX functions, but here, the result is round-tripped through String::fromUTF8() and then utf8(). I don't really have an example of when this would fail, but this is conceptually incorrect and of course wasteful.

I am passing the result of fileSystemRepresentation() to a Posix function: realpath().
realpath() returns a const char* so I have to call String::fromUTF8() to return a String.

I do not see what is wrong with my code.

Also, if you look at the implementation of directoryName(), it is extremely similar:
String directoryName(const String& path)
{
    CString fsRep = fileSystemRepresentation(path);

    if (!fsRep.data() || fsRep.data()[0] == '\0')
        return String();

    return String::fromUTF8(dirname(fsRep.mutableData()));
}
Comment 6 Chris Dumez 2018-07-03 10:50:40 PDT
Created attachment 344196 [details]
Patch
Comment 7 Geoffrey Garen 2018-07-03 13:01:01 PDT
Comment on attachment 344196 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=344196&action=review

> Source/WebCore/Modules/webdatabase/cocoa/DatabaseManagerCocoa.mm:43
> +    setenv("SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS", FileSystem::realPath(databasePath).utf8().data(), 0 /* overwrite */);

A minor point, but I prefer this style for giving symbolic names to constant arguments:

int overwrite = 0;
setenv("SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS", FileSystem::realPath(databasePath).utf8().data(), overwrite);

It's nice when we can document our intent in code. Code has some nice advantages over comments, like compiler validation and debugging and so on.
Comment 8 Geoffrey Garen 2018-07-03 13:15:51 PDT
> The idea behind fileSystemRepresentation() is
> that this is what one passes to POSIX functions

This function calls fileSystemRepresentation() in order to pass the result to the POSIX function realpath(). So, I think that part of the function matches your expectation.

> but here, the result is
> round-tripped through String::fromUTF8() and then utf8(). I don't really
> have an example of when this would fail, but this is conceptually incorrect
> and of course wasteful.

I think your comment here is about the return value type?

Most functions in FileSystemPOSIX.cpp return String.

You could imagine returning CString from this function because that's what POSIX provides, and that's what our caller wants. 

On the other hand, there's a conflict here between POSIX and Windows. Windows returns a buffer of UChar (i.e. String). So returning CString would require getFinalPathName() in FileSystemWin to convert from UChar buffer to CString. Maybe that's the right tradeoff to make POSIX slightly faster?
Comment 9 Chris Dumez 2018-07-03 14:19:45 PDT
Created attachment 344215 [details]
Patch
Comment 10 Geoffrey Garen 2018-07-03 16:23:39 PDT
Comment on attachment 344215 [details]
Patch

I’m going to say r+ to move this fix along — but we can continue to discuss whether there’s a good way to avoid utf8 round tripping.
Comment 11 WebKit Commit Bot 2018-07-03 16:54:53 PDT
Comment on attachment 344215 [details]
Patch

Clearing flags on attachment: 344215

Committed r233487: <https://trac.webkit.org/changeset/233487>
Comment 12 WebKit Commit Bot 2018-07-03 16:54:55 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 Alexey Proskuryakov 2018-07-04 03:12:46 PDT
I like Geoff's suggestion. Alternatively, maybe there is a way to restructure code so that it doesn't even need to be called on Windows. Realpath is a POSIX concept, so adding a Windows function with this name which does nothing is quite misleading.

Or maybe we need to actually do something on Windows too, like https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfullpathnamea
Comment 14 Chris Dumez 2018-07-04 09:37:15 PDT
(In reply to Alexey Proskuryakov from comment #13)
> I like Geoff's suggestion. Alternatively, maybe there is a way to
> restructure code so that it doesn't even need to be called on Windows.
> Realpath is a POSIX concept, so adding a Windows function with this name
> which does nothing is quite misleading.
> Or maybe we need to actually do something on Windows too, like
> https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-
> getfullpathnamea

This is inaccurate, my patch did provide a meaningful Windows implementation.
Note that the very first patch you took a look at did not have a review flag and the lack of windows implementation was one of the reason.
Comment 15 Geoffrey Garen 2018-07-05 13:25:54 PDT
> Or maybe we need to actually do something on Windows too, like
> https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-
> getfullpathnamea

Right, it seems clear that Windows does have a concept of "~" and similar abbreviations in file names.