From c4abfc405acd11e249ea07a99db0f14a05000e1a Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 29 Nov 2012 12:49:41 +0000 Subject: [PATCH] Windows: Fix potential crash in version checker. 1) see if we actually received anything (if http://eduke32.sourceforge.net/VERSION is unavailable, this returns now instead of continuing with nonsensical data) 2) check if we're getting a token from strtok() git-svn-id: https://svn.eduke32.com/eduke32@3244 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/winbits.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/polymer/eduke32/source/winbits.c b/polymer/eduke32/source/winbits.c index 213803574..ba34df49b 100644 --- a/polymer/eduke32/source/winbits.c +++ b/polymer/eduke32/source/winbits.c @@ -42,6 +42,7 @@ int32_t G_GetVersionFromWebsite(char *buffer) struct hostent *h; char *host = "eduke32.sourceforge.net"; char *req = "GET http://eduke32.sourceforge.net/VERSION HTTP/1.0\r\n\r\n\r\n"; + char *tok; char tempbuf[2048],otherbuf[16],ver[16]; SOCKET mysock; @@ -94,13 +95,26 @@ int32_t G_GetVersionFromWebsite(char *buffer) } // initprintf("sent %d bytes\n",bytes_sent); - recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0); + i = recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0); + if (i < 0) + { +// initprintf("update: recv() returned %d\n", i); + return 0; + } + closesocket(mysock); Bmemcpy(&otherbuf,&tempbuf,sizeof(otherbuf)); strtok(otherbuf," "); - if (Batol(strtok(NULL," ")) == 200) + tok = strtok(NULL," "); + if (tok == NULL) + { +// initprintf("update: strtok() produced no token\n"); + return 0; + } + + if (Batol(tok) == 200) { for (i=0; (unsigned)i