Bug 228636 - softlink nw_parameters_allow_sharing_port_with_listener
Summary: softlink nw_parameters_allow_sharing_port_with_listener
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-30 06:34 PDT by youenn fablet
Modified: 2021-07-30 11:09 PDT (History)
5 users (show)

See Also:


Attachments
Patch (3.32 KB, patch)
2021-07-30 06:37 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (4.71 KB, patch)
2021-07-30 09:37 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (4.95 KB, patch)
2021-07-30 09:39 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Rebasing (4.91 KB, patch)
2021-07-30 10:40 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2021-07-30 06:34:38 PDT
softlink nw_parameters_allow_sharing_port_with_listener
Comment 1 youenn fablet 2021-07-30 06:37:16 PDT
Created attachment 434619 [details]
Patch
Comment 2 Darin Adler 2021-07-30 09:02:12 PDT
Comment on attachment 434619 [details]
Patch

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

> Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm:292
> +        String portString;
> +        const char* portValue;
> +#if HAVE(NWPARAMETERS_TRACKER_API)
> +        if (nw_parameters_allow_sharing_port_with_listenerPtr()) {
> +            nw_parameters_allow_sharing_port_with_listenerPtr()(parameters.get(), m_nwListener.get());
> +            portString = String::number(m_address.port());
> +            portValue = portString.utf8().data();

This code is wrong, and already was, and I am surprised it works.

To keep around a pointer to the UTF-8 data we need a CString for the local variable, not a String.

    portString = String::number(m_address.port()).utf8();
    portValue = portString.data();

There are also ways to write this that don’t allocate memory on the heap, using writeIntegerToBuffer, but the above should at least fix the dangerous lifetime bug.
Comment 3 youenn fablet 2021-07-30 09:31:56 PDT
Right, I'll fix this or move to nw_endpoint_create_host_with_numeric_port if possible
Comment 4 youenn fablet 2021-07-30 09:37:01 PDT
Created attachment 434636 [details]
Patch for landing
Comment 5 youenn fablet 2021-07-30 09:39:57 PDT
Created attachment 434637 [details]
Patch for landing
Comment 6 youenn fablet 2021-07-30 10:40:48 PDT
Created attachment 434646 [details]
Rebasing
Comment 7 EWS 2021-07-30 11:08:28 PDT
Committed r280484 (240119@main): <https://commits.webkit.org/240119@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434646 [details].
Comment 8 Radar WebKit Bug Importer 2021-07-30 11:09:19 PDT
<rdar://problem/81334175>