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

_ZN12easywsclient9WebSocket8from_urlERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_:
  546|    175|WebSocket::pointer WebSocket::from_url(const std::string& url, const std::string& origin) {
  547|    175|    return ::from_url(url, true, origin);
  548|    175|}
easywsclient.cpp:_ZN12_GLOBAL__N_18from_urlERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEbS8_:
  457|    175|easywsclient::WebSocket::pointer from_url(const std::string& url, bool useMask, const std::string& origin) {
  458|    175|    char host[512];
  459|    175|    int port;
  460|    175|    char path[512];
  461|    175|    if (url.size() >= 512) {
  ------------------
  |  Branch (461:9): [True: 54, False: 121]
  ------------------
  462|     54|      fprintf(stderr, "ERROR: url size limit exceeded: %s\n", url.c_str());
  463|     54|      return NULL;
  464|     54|    }
  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: 1, False: 120]
  ------------------
  471|      1|    }
  472|    120|    else if (sscanf(url.c_str(), "ws://%[^:/]/%s", host, path) == 2) {
  ------------------
  |  Branch (472:14): [True: 3, False: 117]
  ------------------
  473|      3|        port = 80;
  474|      3|    }
  475|    117|    else if (sscanf(url.c_str(), "ws://%[^:/]:%d", host, &port) == 2) {
  ------------------
  |  Branch (475:14): [True: 65, False: 52]
  ------------------
  476|     65|        path[0] = '\0';
  477|     65|    }
  478|     52|    else if (sscanf(url.c_str(), "ws://%[^:/]", host) == 1) {
  ------------------
  |  Branch (478:14): [True: 36, False: 16]
  ------------------
  479|     36|        port = 80;
  480|     36|        path[0] = '\0';
  481|     36|    }
  482|     16|    else {
  483|     16|        fprintf(stderr, "ERROR: Could not parse WebSocket url: %s\n", url.c_str());
  484|     16|        return NULL;
  485|     16|    }
  486|       |    //fprintf(stderr, "easywsclient: connecting: host=%s port=%d path=/%s\n", host, port, path);
  487|    105|    socket_t sockfd = hostname_connect(host, port);
  488|    105|    if (sockfd == INVALID_SOCKET) {
  ------------------
  |  |   61|    105|        #define INVALID_SOCKET (-1)
  ------------------
  |  Branch (488:9): [True: 7, False: 98]
  ------------------
  489|      7|        fprintf(stderr, "Unable to connect to %s:%d\n", host, port);
  490|      7|        return NULL;
  491|      7|    }
  492|     98|    {
  493|       |        // XXX: this should be done non-blocking,
  494|     98|        char line[1024];
  495|     98|        int status;
  496|     98|        int i;
  497|     98|        snprintf(line, 1024, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0);
  498|     98|        if (port == 80) {
  ------------------
  |  Branch (498:13): [True: 33, False: 65]
  ------------------
  499|     33|            snprintf(line, 1024, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0);
  500|     33|        }
  501|     65|        else {
  502|     65|            snprintf(line, 1024, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0);
  503|     65|        }
  504|     98|        snprintf(line, 1024, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0);
  505|     98|        snprintf(line, 1024, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0);
  506|     98|        if (!origin.empty()) {
  ------------------
  |  Branch (506:13): [True: 0, False: 98]
  ------------------
  507|      0|            snprintf(line, 1024, "Origin: %s\r\n", origin.c_str()); ::send(sockfd, line, strlen(line), 0);
  508|      0|        }
  509|     98|        snprintf(line, 1024, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);
  510|     98|        snprintf(line, 1024, "Sec-WebSocket-Version: 13\r\n"); ::send(sockfd, line, strlen(line), 0);
  511|     98|        snprintf(line, 1024, "\r\n"); ::send(sockfd, line, strlen(line), 0);
  512|    294|        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: 196, False: 98]
  |  Branch (512:31): [True: 98, False: 0]
  |  Branch (512:43): [True: 0, False: 98]
  |  Branch (512:64): [True: 0, False: 0]
  |  Branch (512:95): [True: 0, False: 196]
  ------------------
  513|     98|        line[i] = 0;
  514|     98|        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: 98]
  ------------------
  515|     98|        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: 98, 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|    105|socket_t hostname_connect(const std::string& hostname, int port) {
   84|    105|    struct addrinfo hints;
   85|    105|    struct addrinfo *result;
   86|    105|    struct addrinfo *p;
   87|    105|    int ret;
   88|    105|    socket_t sockfd = INVALID_SOCKET;
  ------------------
  |  |   61|    105|        #define INVALID_SOCKET (-1)
  ------------------
   89|    105|    char sport[16];
   90|    105|    memset(&hints, 0, sizeof(hints));
   91|    105|    hints.ai_family = AF_UNSPEC;
   92|    105|    hints.ai_socktype = SOCK_STREAM;
   93|    105|    snprintf(sport, 16, "%d", port);
   94|    105|    if ((ret = getaddrinfo(hostname.c_str(), sport, &hints, &result)) != 0)
  ------------------
  |  Branch (94:9): [True: 98, False: 7]
  ------------------
   95|     98|    {
   96|     98|      fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
   97|     98|      return 1;
   98|     98|    }
   99|     17|    for(p = result; p != NULL; p = p->ai_next)
  ------------------
  |  Branch (99:21): [True: 10, False: 7]
  ------------------
  100|     10|    {
  101|     10|        sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
  102|     10|        if (sockfd == INVALID_SOCKET) { continue; }
  ------------------
  |  |   61|     10|        #define INVALID_SOCKET (-1)
  ------------------
  |  Branch (102:13): [True: 0, False: 10]
  ------------------
  103|     10|        if (connect(sockfd, p->ai_addr, p->ai_addrlen) != SOCKET_ERROR) {
  ------------------
  |  |   64|     10|        #define SOCKET_ERROR   (-1)
  ------------------
  |  Branch (103:13): [True: 0, False: 10]
  ------------------
  104|      0|            break;
  105|      0|        }
  106|     10|        closesocket(sockfd);
  ------------------
  |  |   66|     10|    #define closesocket(s) ::close(s)
  ------------------
  107|     10|        sockfd = INVALID_SOCKET;
  ------------------
  |  |   61|     10|        #define INVALID_SOCKET (-1)
  ------------------
  108|     10|    }
  109|      7|    freeaddrinfo(result);
  110|      7|    return sockfd;
  111|    105|}

