Skip to content

Commit 9bc8efb

Browse files
bitcdhbaird
authored andcommitted
Increase max URL length
1 parent 9b87dc4 commit 9bc8efb

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

easywsclient.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ class _RealWebSocket : public easywsclient::WebSocket
429429

430430

431431
easywsclient::WebSocket::pointer from_url(const std::string& url, bool useMask, const std::string& origin) {
432-
char host[128];
432+
char host[512];
433433
int port;
434-
char path[128];
435-
if (url.size() >= 128) {
434+
char path[512];
435+
if (url.size() >= 512) {
436436
fprintf(stderr, "ERROR: url size limit exceeded: %s\n", url.c_str());
437437
return NULL;
438438
}
@@ -465,31 +465,31 @@ easywsclient::WebSocket::pointer from_url(http://github.com/const%20std::string&%20url,%20bool%20useMask,%3C/div%3E%3C/code%3E%3C/div%3E%3C/td%3E%3C/tr%3E%3Ctr%20class=%22diff-line-row%22%3E%3Ctd%20data-grid-cell-id=%22diff-80406e8d50d774a73e7d4d97be2486b7b07f319da1ac68e180dd82cc77578122-465-465-0%22%20data-selected=%22false%22%20role=%22gridcell%22%20style=%22background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">465
465
}
466466
{
467467
// XXX: this should be done non-blocking,
468-
char line[256];
468+
char line[1024];
469469
int status;
470470
int i;
471-
snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0);
471+
snprintf(line, 1024, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0);
472472
if (port == 80) {
473-
snprintf(line, 256, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0);
473+
snprintf(line, 1024, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0);
474474
}
475475
else {
476-
snprintf(line, 256, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0);
476+
snprintf(line, 1024, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0);
477477
}
478-
snprintf(line, 256, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0);
479-
snprintf(line, 256, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0);
478+
snprintf(line, 1024, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0);
479+
snprintf(line, 1024, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0);
480480
if (!origin.empty()) {
481-
snprintf(line, 256, "Origin: %s\r\n", origin.c_str()); ::send(sockfd, line, strlen(line), 0);
481+
snprintf(line, 1024, "Origin: %s\r\n", origin.c_str()); ::send(sockfd, line, strlen(line), 0);
482482
}
483-
snprintf(line, 256, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);
484-
snprintf(line, 256, "Sec-WebSocket-Version: 13\r\n"); ::send(sockfd, line, strlen(line), 0);
485-
snprintf(line, 256, "\r\n"); ::send(sockfd, line, strlen(line), 0);
486-
for (i = 0; i < 2 || (i < 255 && line[i-2] != '\r' && line[i-1] != '\n'); ++i) { if (recv(sockfd, line+i, 1, 0) == 0) { return NULL; } }
483+
snprintf(line, 1024, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);
484+
snprintf(line, 1024, "Sec-WebSocket-Version: 13\r\n"); ::send(sockfd, line, strlen(line), 0);
485+
snprintf(line, 1024, "\r\n"); ::send(sockfd, line, strlen(line), 0);
486+
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; } }
487487
line[i] = 0;
488-
if (i == 255) { fprintf(stderr, "ERROR: Got invalid status line connecting to: %s\n", url.c_str()); return NULL; }
488+
if (i == 1023) { fprintf(stderr, "ERROR: Got invalid status line connecting to: %s\n", url.c_str()); return NULL; }
489489
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; }
490490
// TODO: verify response headers,
491491
while (true) {
492-
for (i = 0; i < 2 || (i < 255 && line[i-2] != '\r' && line[i-1] != '\n'); ++i) { if (recv(sockfd, line+i, 1, 0) == 0) { return NULL; } }
492+
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; } }
493493
if (line[0] == '\r' && line[1] == '\n') { break; }
494494
}
495495
}

0 commit comments

Comments
 (0)