Azure / azure-c-shared-utility

Azure C SDKs common code
Other
111 stars 204 forks source link

Access Violation in "uws_client.c" #607

Closed powertomato closed 4 months ago

powertomato commented 1 year ago

The issue occurs in on_underlying_io_open_complete after a uws_client_create and subsequent uws_client_open_async call. Here is the snippet I'm using:

    UWS_CLIENT_HANDLE uws_client = uws_client_create("192.168.1.21", 80, "/", false, NULL, 0);
    if (uws_client == NULL) {
        (void)printf("WS Init Failed\r\n");
        return;
    }
    int ret = uws_client_open_async(uws_client, 
        on_ws_open_complete, uws_client, 
        on_ws_frame_receive, NULL, 
        on_peer_closed, NULL,
        on_ws_error, NULL);    
    if (ret != 0) {
        (void)printf("WS Open Failed\r\n");
    } else {
        (void)printf("WS Open Success\r\n");
    }

When I specify the parameter protocols to NULL, on the server I still receive the "Sec-WebSocket-Protocol" entry with the value "Protocol: %s". As I understand it, if protocol == NULL and count==0, the header entry should be omitted. Further the value received at the server looks suspiciously like an access violation.

Looking at the code, I think this is indeed the case:

In the following line the protocols array is set to NULL: https://github.com/Azure/azure-c-shared-utility/blob/718ec00a1df4917f1ee8aa528bdfa37e56bd8e92/src/uws_client.c#L291

and later, as a connection is opened, there are no NULL checks, but still the protocols[0] value is used: https://github.com/Azure/azure-c-shared-utility/blob/718ec00a1df4917f1ee8aa528bdfa37e56bd8e92/src/uws_client.c#L825 https://github.com/Azure/azure-c-shared-utility/blob/718ec00a1df4917f1ee8aa528bdfa37e56bd8e92/src/uws_client.c#L849

There are couple of other places not relevant for "Sec-WebSocket-Protocol", but probably still require a fix.

ericwolz commented 1 year ago

All the current usage of this library specifies a protocol (AMQP/MQTT). Usage without a protocol is currently not supported or tested.

ewertons commented 4 months ago

Closing this issue since this library is specific for being used by azure-iot-sdk-c. Direct use is not supported nor maintained. Thanks, Azure IoT SDKs Team