Bug 113030 - bundle-ids need to be sanitized before using them in filesystem paths
Summary: bundle-ids need to be sanitized before using them in filesystem paths
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.8
: P1 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-03-22 02:35 PDT by Simon Cooper
Modified: 2013-03-26 10:23 PDT (History)
3 users (show)

See Also:


Attachments
Patch (1.50 KB, patch)
2013-03-22 03:06 PDT, Simon Cooper
no flags Details | Formatted Diff | Diff
Patch (2.75 KB, patch)
2013-03-26 03:09 PDT, Simon Cooper
no flags Details | Formatted Diff | Diff
Patch (2.77 KB, patch)
2013-03-26 03:28 PDT, Simon Cooper
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Cooper 2013-03-22 02:35:31 PDT
When choosing / looking for a specialized Sandbox for a Plugin the bundle-id needs to be sanitized before using it to construct a filesystem name to look up.  The “/“ character should not be allowed and transformed into something else - e.g. “:”
Comment 1 Simon Cooper 2013-03-22 03:06:15 PDT
Created attachment 194493 [details]
Patch
Comment 2 Alexey Proskuryakov 2013-03-22 10:03:25 PDT
Comment on attachment 194493 [details]
Patch

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

r- for the leak.

I suggest using WTF types more here. Something like:

String bundleIdentifier = CFBundleGetIdentifier(pluginBundle.get());
if (bundleIdentifier.isEmpty())
    return String();

// Fold all / characters to : to prevent the plugin bundle-id from trying to escape the profile directory.
bundleIdentifier.replace('/', ':');

RetainPtr<CFStringRef> sandboxFileName = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%@.sb"), bundleIdentifier.createCFString().get()));

Or you could go even further, and use String::format instead of CFStringCreateWithFormat too.

> Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm:300
> +    CFMutableStringRef bundleIdentifier = CFStringCreateMutableCopy(0, 0, bundleID);

This allocated string needs to be released. We normally use a RetainPtr wrapper to automate it, like this:

RetainPtr<CFMutableStringRef> bundleIdentifier = adoptCF(CFStringCreateMutableCopy(0, 0, bundleID));

I think that the distinction between bundleID and bundleIdentifier names is too subtle.

> Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm:311
>      RetainPtr<CFStringRef> sandboxFileName = CFStringCreateWithFormat(0, 0, CFSTR("%@.sb"), bundleIdentifier);

This is existing code, but it also leaks. The reason is that this RetainPtr constructor retains the value, so the releases are not balanced.

This line should have used adoptCF, like the one above.
Comment 3 Alexey Proskuryakov 2013-03-22 10:04:51 PDT
<rdar://problem/13300254>
Comment 4 Alexey Proskuryakov 2013-03-22 10:05:38 PDT
Oh, and the patch lacks a ChangeLog for some reason.
Comment 5 Simon Cooper 2013-03-26 03:09:15 PDT
Created attachment 195045 [details]
Patch
Comment 6 Simon Cooper 2013-03-26 03:13:15 PDT
Comment on attachment 195045 [details]
Patch

*sigh* this attachment is not what I intended to upload.
Comment 7 Simon Cooper 2013-03-26 03:28:32 PDT
Created attachment 195047 [details]
Patch
Comment 8 Alexey Proskuryakov 2013-03-26 09:53:35 PDT
Comment on attachment 195047 [details]
Patch

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

You didn't formally request commit queue, but since you are not a committer yet as far as I know, I'm assuming that you want the patch to be automatically landed.

> Source/WebKit2/ChangeLog:12
> +        filesystem name to look up. The â/â character should not be allowed
> +        and transformed into something else, in this case a â:â

Not sure if quotation marks actually got garbled, but they certainly look garbled now. Did you use a UTF-8 aware editor?
Comment 9 WebKit Review Bot 2013-03-26 10:23:37 PDT
Comment on attachment 195047 [details]
Patch

Clearing flags on attachment: 195047

Committed r146902: <http://trac.webkit.org/changeset/146902>
Comment 10 WebKit Review Bot 2013-03-26 10:23:41 PDT
All reviewed patches have been landed.  Closing bug.