Azure/azure-c-shared-utility

Access Violation in "uws_client.c"

powertomato opened this issue · 2 comments

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:

result->protocols = NULL;

and later, as a connection is opened, there are no NULL checks, but still the protocols[0] value is used:

upgrade_request_length = (int)(strlen(upgrade_request_format) + strlen(uws_client->resource_name)+strlen(uws_client->hostname) + strlen(base64_nonce_chars) + strlen(uws_client->protocols[0].protocol) + strlen(request_headers) + 5);

uws_client->protocols[0].protocol,

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

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

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