Bug 228636

Summary: softlink nw_parameters_allow_sharing_port_with_listener
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebRTCAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric.carlson, ews-watchlist, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch for landing
none
Patch for landing
none
Rebasing none

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>