Skip to content

Commit dc78dee

Browse files
y637F9QQ2xbk138
authored andcommitted
libvncserver: fix NULL pointer dereferences in httpd proxy handlers
httpProcessInput() passes the return value of strchr() to atoi() and strncmp() without checking for NULL. If a CONNECT request contains no colon, or a GET request contains no slash, strchr() returns NULL, leading to a segmentation fault. Add NULL checks before using the strchr() return values.
1 parent 9664466 commit dc78dee

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/libvncserver/httpd.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ httpProcessInput(rfbScreenInfoPtr rfbScreen)
353353

354354

355355
/* Process the request. */
356-
if(rfbScreen->httpEnableProxyConnect) {
356+
if(rfbScreen->httpEnableProxyConnect) {
357357
const static char* PROXY_OK_STR = "HTTP/1.0 200 OK\r\nContent-Type: octet-stream\r\nPragma: no-cache\r\n\r\n";
358358
if(!strncmp(buf, "CONNECT ", 8)) {
359-
if(atoi(strchr(buf, ':')+1)!=rfbScreen->port) {
359+
char *colon = strchr(buf, ':');
360+
if(colon == NULL || atoi(colon+1)!=rfbScreen->port) {
360361
rfbErr("httpd: CONNECT format invalid.\n");
361362
rfbWriteExact(&cl,INVALID_REQUEST_STR, strlen(INVALID_REQUEST_STR));
362363
httpCloseSock(rfbScreen);
@@ -369,14 +370,17 @@ httpProcessInput(rfbScreenInfoPtr rfbScreen)
369370
rfbScreen->httpSock = RFB_INVALID_SOCKET;
370371
return;
371372
}
372-
if (!strncmp(buf, "GET ",4) && !strncmp(strchr(buf,'/'),"/proxied.connection HTTP/1.", 27)) {
373-
/* proxy connection */
374-
rfbLog("httpd: client asked for /proxied.connection\n");
375-
rfbWriteExact(&cl,PROXY_OK_STR,strlen(PROXY_OK_STR));
376-
rfbNewClientConnection(rfbScreen,rfbScreen->httpSock);
377-
rfbScreen->httpSock = RFB_INVALID_SOCKET;
378-
return;
379-
}
373+
if (!strncmp(buf, "GET ",4)) {
374+
char *slash = strchr(buf, '/');
375+
if (slash != NULL && !strncmp(slash,"/proxied.connection HTTP/1.", 27)) {
376+
/* proxy connection */
377+
rfbLog("httpd: client asked for /proxied.connection\n");
378+
rfbWriteExact(&cl,PROXY_OK_STR,strlen(PROXY_OK_STR));
379+
rfbNewClientConnection(rfbScreen,rfbScreen->httpSock);
380+
rfbScreen->httpSock = RFB_INVALID_SOCKET;
381+
return;
382+
}
383+
}
380384
}
381385

382386
if (strncmp(buf, "GET ", 4)) {

0 commit comments

Comments
 (0)