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

_ZN12easywsclient9WebSocket8from_urlERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_:
  546|    177|WebSocket::pointer WebSocket::from_url(const std::string& url, const std::string& origin) {
  547|    177|    return ::from_url(url, true, origin);
  548|    177|}
easywsclient.cpp:_ZN12_GLOBAL__N_18from_urlERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEbS8_:
  457|    177|easywsclient::WebSocket::pointer from_url(const std::string& url, bool useMask, const std::string& origin) {
  458|    177|    char host[512];
  459|    177|    int port;
  460|    177|    char path[512];
  461|    177|    if (url.size() >= 512) {
  ------------------
  |  Branch (461:9): [True: 54, False: 123]
  ------------------
  462|     54|      fprintf(stderr, "ERROR: url size limit exceeded: %s\n", url.c_str());
  463|     54|      return NULL;
  464|     54|    }
  465|    123|    if (origin.size() >= 200) {
  ------------------
  |  Branch (465:9): [True: 0, False: 123]
  ------------------
  466|      0|      fprintf(stderr, "ERROR: origin size limit exceeded: %s\n", origin.c_str());
  467|      0|      return NULL;
  468|      0|    }
  469|    123|    if (false) { }
  ------------------
  |  Branch (469:9): [Folded, False: 123]
  ------------------
  470|    123|    else if (sscanf(url.c_str(), "ws://%[^:/]:%d/%s", host, &port, path) == 3) {
  ------------------
  |  Branch (470:14): [True: 2, False: 121]
  ------------------
  471|      2|    }
  472|    121|    else if (sscanf(url.c_str(), "ws://%[^:/]/%s", host, path) == 2) {
  ------------------
  |  Branch (472:14): [True: 4, False: 117]
  ------------------
  473|      4|        port = 80;
  474|      4|    }
  475|    117|    else if (sscanf(url.c_str(), "ws://%[^:/]:%d", host, &port) == 2) {
  ------------------
  |  Branch (475:14): [True: 64, False: 53]
  ------------------
  476|     64|        path[0] = '\0';
  477|     64|    }
  478|     53|    else if (sscanf(url.c_str(), "ws://%[^:/]", host) == 1) {
  ------------------
  |  Branch (478:14): [True: 38, False: 15]
  ------------------
  479|     38|        port = 80;
  480|     38|        path[0] = '\0';
  481|     38|    }
  482|     15|    else {
  483|     15|        fprintf(stderr, "ERROR: Could not parse WebSocket url: %s\n", url.c_str());
  484|     15|        return NULL;
  485|     15|    }
  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: 4, False: 104]
  ------------------
  489|      4|        fprintf(stderr, "Unable to connect to %s:%d\n", host, port);
  490|      4|        return NULL;
  491|      4|    }
  492|    104|    {
  493|       |        // XXX: this should be done non-blocking,
  494|    104|        char line[1024];
  495|    104|        int status;
  496|    104|        int i;
  497|    104|        snprintf(line, 1024, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0);
  498|    104|        if (port == 80) {
  ------------------
  |  Branch (498:13): [True: 38, False: 66]
  ------------------
  499|     38|            snprintf(line, 1024, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0);
  500|     38|        }
  501|     66|        else {
  502|     66|            snprintf(line, 1024, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0);
  503|     66|        }
  504|    104|        snprintf(line, 1024, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0);
  505|    104|        snprintf(line, 1024, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0);
  506|    104|        if (!origin.empty()) {
  ------------------
  |  Branch (506:13): [True: 0, False: 104]
  ------------------
  507|      0|            snprintf(line, 1024, "Origin: %s\r\n", origin.c_str()); ::send(sockfd, line, strlen(line), 0);
  508|      0|        }
  509|    104|        snprintf(line, 1024, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);
  510|    104|        snprintf(line, 1024, "Sec-WebSocket-Version: 13\r\n"); ::send(sockfd, line, strlen(line), 0);
  511|    104|        snprintf(line, 1024, "\r\n"); ::send(sockfd, line, strlen(line), 0);
  512|    312|        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: 208, False: 104]
  |  Branch (512:31): [True: 104, False: 0]
  |  Branch (512:43): [True: 0, False: 104]
  |  Branch (512:64): [True: 0, False: 0]
  |  Branch (512:95): [True: 0, False: 208]
  ------------------
  513|    104|        line[i] = 0;
  514|    104|        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: 104]
  ------------------
  515|    104|        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: 104, 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: 104, False: 4]
  ------------------
   95|    104|    {
   96|    104|      fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
   97|    104|      return 1;
   98|    104|    }
   99|     10|    for(p = result; p != NULL; p = p->ai_next)
  ------------------
  |  Branch (99:21): [True: 6, False: 4]
  ------------------
  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|      4|    freeaddrinfo(result);
  110|      4|    return sockfd;
  111|    108|}

