]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
better error handling for overlong srcon commands
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Apr 2009 07:32:54 +0000 (07:32 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Apr 2009 07:32:54 +0000 (07:32 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8887 d7cf8633-e32d-0410-b094-e92efae38249

hmac.c
hmac.h
host_cmd.c
netconn.c

diff --git a/hmac.c b/hmac.c
index de44162796b6339164e4c41dd88009bae76c3c43..bd97ba43fd2c7321d6d5229e80c98c4c0a27b01e 100644 (file)
--- 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 d2a327b6ea0f61c12cff5afb8d258a2e020541bf..4d6358ae1cf436ceb436bf23e357a9404b61c717 100644 (file)
--- 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,
index c8c7889673de61e38c6d88e1ab83f535b1d52c9e..76807ce6b33c3d83016592d71f1656a5551f2179 100644 (file)
@@ -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
                {
index 93199c116a7a8b7319200cb0c9a7b1372c78867e..ce3f0913b2f210274861bec2142ae09c8312e51e 100755 (executable)
--- 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);
 }