From: divverent Date: Thu, 9 Apr 2009 07:32:54 +0000 (+0000) Subject: better error handling for overlong srcon commands X-Git-Tag: xonotic-v0.1.0preview~1723 X-Git-Url: http://de.git.xonotic.org/?a=commitdiff_plain;h=01b29650876b1f991ac2e8fe0c0a54b73c43204e;p=xonotic%2Fdarkplaces.git better error handling for overlong srcon commands git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8887 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/hmac.c b/hmac.c index de441627..bd97ba43 100644 --- a/hmac.c +++ b/hmac.c @@ -1,7 +1,7 @@ #include "quakedef.h" #include "hmac.h" -void hmac( +qboolean hmac( hashfunc_t hfunc, int hlen, int hblock, unsigned char *out, unsigned char *in, int n, @@ -15,15 +15,15 @@ void hmac( int i; if(sizeof(hashbuf) < (size_t) hlen) - Host_Error("Invalid hash function used for HMAC - too long hash length"); + return false; if(sizeof(k_xor_ipad) < (size_t) hblock) - Host_Error("Invalid hash function used for HMAC - too long hash block length"); + return false; if(sizeof(k_xor_ipad) < (size_t) hlen) - Host_Error("Invalid hash function used for HMAC - too long hash length"); + return false; if(sizeof(catbuf) < (size_t) hblock + (size_t) hlen) - Host_Error("Invalid hash function used for HMAC - too long hash block length"); + return false; if(sizeof(catbuf) < (size_t) hblock + (size_t) n) - Host_Error("Invalid hash function used for HMAC - too long message length"); + return false; if(k > hblock) { @@ -56,4 +56,5 @@ void hmac( memcpy(catbuf, k_xor_opad, hblock); memcpy(catbuf + hblock, hashbuf, hlen); hfunc(out, catbuf, hblock + hlen); + return true; } diff --git a/hmac.h b/hmac.h index d2a327b6..4d6358ae 100644 --- a/hmac.h +++ b/hmac.h @@ -2,7 +2,7 @@ #define HMAC_H typedef void (*hashfunc_t) (unsigned char *out, unsigned char *in, int n); -void hmac( +qboolean hmac( hashfunc_t hfunc, int hlen, int hblock, unsigned char *out, unsigned char *in, int n, diff --git a/host_cmd.c b/host_cmd.c index c8c78896..76807ce6 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -2390,10 +2390,12 @@ void Host_Rcon_f (void) // credit: taken from QuakeWorld char argbuf[1500]; dpsnprintf(argbuf, sizeof(argbuf), "%ld %s", (long) time(NULL), Cmd_Args()); memcpy(buf, "\377\377\377\377srcon HMAC-MD4 TIME ", 24); - HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, strlen(rcon_password.string)); - buf[40] = ' '; - strlcpy(buf + 41, argbuf, sizeof(buf) - 41); - NetConn_Write(mysocket, buf, 41 + strlen(buf + 41), &to); + if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, strlen(rcon_password.string))) + { + buf[40] = ' '; + strlcpy(buf + 41, argbuf, sizeof(buf) - 41); + NetConn_Write(mysocket, buf, 41 + strlen(buf + 41), &to); + } } else { diff --git a/netconn.c b/netconn.c index 93199c11..ce3f0913 100755 --- a/netconn.c +++ b/netconn.c @@ -2192,7 +2192,9 @@ qboolean hmac_mdfour_matching(const char *password, const char *hash, const char if(abs(t1 - t2) > rcon_secure_maxdiff.integer) return false; - HMAC_MDFOUR_16BYTES((unsigned char *) mdfourbuf, (unsigned char *) s, slen, (unsigned char *) password, strlen(password)); + if(!HMAC_MDFOUR_16BYTES((unsigned char *) mdfourbuf, (unsigned char *) s, slen, (unsigned char *) password, strlen(password))) + return false; + return !memcmp(mdfourbuf, hash, 16); }