LLVMFuzzerTestOneInput:
   22|    174|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   23|    174|  std::string str(reinterpret_cast<const char*>(data), size);
   24|    174|  easywsclient::WebSocket::from_url(str);
   25|    174|  return 0;
   26|    174|}

_ZN12easywsclient9WebSocket8from_urlERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_:
  546|    174|WebSocket::pointer WebSocket::from_url(const std::string& url, const std::string& origin) {
  547|    174|    return ::from_url(url, true, origin);
  548|    174|}
easywsclient.cpp:_ZN12_GLOBAL__N_18from_urlERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEbS8_:
  457|    174|easywsclient::WebSocket::pointer from_url(const std::string& url, bool useMask, const std::string& origin) {
  458|    174|    char host[512];
  459|    174|    int port;
  460|    174|    char path[512];
  461|    174|    if (url.size() >= 512) {
  ------------------
  |  Branch (461:9): [True: 53, False: 121]
  ------------------
  462|     53|      fprintf(stderr, "ERROR: url size limit exceeded: %s\n", url.c_str());
  463|     53|      return NULL;
  464|     53|    }
  465|    121|    if (origin.size() >= 200) {
  ------------------
  |  Branch (465:9): [True: 0, False: 121]
  ------------------
  466|      0|      fprintf(stderr, "ERROR: origin size limit exceeded: %s\n", origin.c_str());
  467|      0|      return NULL;
  468|      0|    }
  469|    121|    if (false) { }
  ------------------
  |  Branch (469:9): [Folded, False: 121]
  ------------------
  470|    121|    else if (sscanf(url.c_str(), "ws://%[^:/]:%d/%s", host, &port, path) == 3) {
  ------------------
  |  Branch (470:14): [True: 2, False: 119]
  ------------------
  471|      2|    }
  472|    119|    else if (sscanf(url.c_str(), "ws://%[^:/]/%s", host, path) == 2) {
  ------------------
  |  Branch (472:14): [True: 5, False: 114]
  ------------------
  473|      5|        port = 80;
  474|      5|    }
  475|    114|    else if (sscanf(url.c_str(), "ws://%[^:/]:%d", host, &port) == 2) {
  ------------------
  |  Branch (475:14): [True: 62, False: 52]
  ------------------
  476|     62|        path[0] = '\0';
  477|     62|    }
  478|     52|    else if (sscanf(url.c_str(), "ws://%[^:/]", host) == 1) {
  ------------------
  |  Branch (478:14): [True: 39, False: 13]
  ------------------
  479|     39|        port = 80;
  480|     39|        path[0] = '\0';
  481|     39|    }
  482|     13|    else {
  483|     13|        fprintf(stderr, "ERROR: Could not parse WebSocket url: %s\n", url.c_str());
  484|     13|        return NULL;
  485|     13|    }
  486|       |    //fprintf(stderr, "easywsclient: connecting: host=%s port=%d path=/%s\n", host, port, path);
  487|    108|    socket_t sockfd = hostname_connect(host, port);
  488|    108|    if (sockfd == INVALID_SOCKET) {
  ------------------
  |  |   61|    108|        #define INVALID_SOCKET (-1)
  ------------------
  |  Branch (488:9): [True: 5, False: 103]
  ------------------
  489|      5|        fprintf(stderr, "Unable to connect to %s:%d\n", host, port);
  490|      5|        return NULL;
  491|      5|    }
  492|    103|    {
  493|       |        // XXX: this should be done non-blocking,
  494|    103|        char line[1024];
  495|    103|        int status;
  496|    103|        int i;
  497|    103|        snprintf(line, 1024, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0);
  498|    103|        if (port == 80) {
  ------------------
  |  Branch (498:13): [True: 39, False: 64]
  ------------------
  499|     39|            snprintf(line, 1024, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0);
  500|     39|        }
  501|     64|        else {
  502|     64|            snprintf(line, 1024, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0);
  503|     64|        }
  504|    103|        snprintf(line, 1024, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0);
  505|    103|        snprintf(line, 1024, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0);
  506|    103|        if (!origin.empty()) {
  ------------------
  |  Branch (506:13): [True: 0, False: 103]
  ------------------
  507|      0|            snprintf(line, 1024, "Origin: %s\r\n", origin.c_str()); ::send(sockfd, line, strlen(line), 0);
  508|      0|        }
  509|    103|        snprintf(line, 1024, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);
  510|    103|        snprintf(line, 1024, "Sec-WebSocket-Version: 13\r\n"); ::send(sockfd, line, strlen(line), 0);
  511|    103|        snprintf(line, 1024, "\r\n"); ::send(sockfd, line, strlen(line), 0);
  512|    309|        for (i = 0; i < 2 || (i < 1023 && line[i-2] != '\r' && line[i-1] != '\n'); ++i) { if (recv(sockfd, line+i, 1, 0) == 0) { return NULL; } }
  ------------------
  |  Branch (512:21): [True: 206, False: 103]
  |  Branch (512:31): [True: 103, False: 0]
  |  Branch (512:43): [True: 0, False: 103]
  |  Branch (512:64): [True: 0, False: 0]
  |  Branch (512:95): [True: 0, False: 206]
  ------------------
  513|    103|        line[i] = 0;
  514|    103|        if (i == 1023) { fprintf(stderr, "ERROR: Got invalid status line connecting to: %s\n", url.c_str()); return NULL; }
  ------------------
  |  Branch (514:13): [True: 0, False: 103]
  ------------------
  515|    103|        if (sscanf(line, "HTTP/1.1 %d", &status) != 1 || status != 101) { fprintf(stderr, "ERROR: Got bad status connecting to %s: %s", url.c_str(), line); return NULL; }
  ------------------
  |  Branch (515:13): [True: 103, False: 0]
  |  Branch (515:58): [True: 0, False: 0]
  ------------------
  516|       |        // TODO: verify response headers,
  517|      0|        while (true) {
  ------------------
  |  Branch (517:16): [True: 0, Folded]
  ------------------
  518|      0|            for (i = 0; i < 2 || (i < 1023 && line[i-2] != '\r' && line[i-1] != '\n'); ++i) { if (recv(sockfd, line+i, 1, 0) == 0) { return NULL; } }
  ------------------
  |  Branch (518:25): [True: 0, False: 0]
  |  Branch (518:35): [True: 0, False: 0]
  |  Branch (518:47): [True: 0, False: 0]
  |  Branch (518:68): [True: 0, False: 0]
  |  Branch (518:99): [True: 0, False: 0]
  ------------------
  519|      0|            if (line[0] == '\r' && line[1] == '\n') { break; }
  ------------------
  |  Branch (519:17): [True: 0, False: 0]
  |  Branch (519:36): [True: 0, False: 0]
  ------------------
  520|      0|        }
  521|      0|    }
  522|      0|    int flag = 1;
  523|      0|    setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*) &flag, sizeof(flag)); // Disable Nagle's algorithm
  524|       |#ifdef _WIN32
  525|       |    u_long on = 1;
  526|       |    ioctlsocket(sockfd, FIONBIO, &on);
  527|       |#else
  528|      0|    fcntl(sockfd, F_SETFL, O_NONBLOCK);
  529|      0|#endif
  530|       |    //fprintf(stderr, "Connected to: %s\n", url.c_str());
  531|      0|    return easywsclient::WebSocket::pointer(new _RealWebSocket(sockfd, useMask));
  532|      0|}
easywsclient.cpp:_ZN12_GLOBAL__N_116hostname_connectERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi:
   83|    108|socket_t hostname_connect(const std::string& hostname, int port) {
   84|    108|    struct addrinfo hints;
   85|    108|    struct addrinfo *result;
   86|    108|    struct addrinfo *p;
   87|    108|    int ret;
   88|    108|    socket_t sockfd = INVALID_SOCKET;
  ------------------
  |  |   61|    108|        #define INVALID_SOCKET (-1)
  ------------------
   89|    108|    char sport[16];
   90|    108|    memset(&hints, 0, sizeof(hints));
   91|    108|    hints.ai_family = AF_UNSPEC;
   92|    108|    hints.ai_socktype = SOCK_STREAM;
   93|    108|    snprintf(sport, 16, "%d", port);
   94|    108|    if ((ret = getaddrinfo(hostname.c_str(), sport, &hints, &result)) != 0)
  ------------------
  |  Branch (94:9): [True: 103, False: 5]
  ------------------
   95|    103|    {
   96|    103|      fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
   97|    103|      return 1;
   98|    103|    }
   99|     11|    for(p = result; p != NULL; p = p->ai_next)
  ------------------
  |  Branch (99:21): [True: 6, False: 5]
  ------------------
  100|      6|    {
  101|      6|        sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
  102|      6|        if (sockfd == INVALID_SOCKET) { continue; }
  ------------------
  |  |   61|      6|        #define INVALID_SOCKET (-1)
  ------------------
  |  Branch (102:13): [True: 0, False: 6]
  ------------------
  103|      6|        if (connect(sockfd, p->ai_addr, p->ai_addrlen) != SOCKET_ERROR) {
  ------------------
  |  |   64|      6|        #define SOCKET_ERROR   (-1)
  ------------------
  |  Branch (103:13): [True: 0, False: 6]
  ------------------
  104|      0|            break;
  105|      0|        }
  106|      6|        closesocket(sockfd);
  ------------------
  |  |   66|      6|    #define closesocket(s) ::close(s)
  ------------------
  107|      6|        sockfd = INVALID_SOCKET;
  ------------------
  |  |   61|      6|        #define INVALID_SOCKET (-1)
  ------------------
  108|      6|    }
  109|      5|    freeaddrinfo(result);
  110|      5|    return sockfd;
  111|    108|}

