Skip to content

Commit b8de02f

Browse files
authored
Fix for buffer overflow issue #728 (#729)
* #728 Buffer overflow error * Make sure old long passwords work as well
1 parent 71e343f commit b8de02f

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/fbmath.c

+6-21
Original file line numberDiff line numberDiff line change
@@ -584,26 +584,6 @@ rnd(void *buffer)
584584
*
585585
*********************************************************************/
586586

587-
#ifdef USE_SSL
588-
static void
589-
PBKDF2_HMAC_SHA_512(const char* pass, const unsigned char* salt,
590-
int32_t iterations, uint32_t outputBytes,
591-
char* hexResult)
592-
{
593-
unsigned int i;
594-
unsigned char* digest;
595-
596-
digest = (unsigned char*)malloc(outputBytes);
597-
598-
PKCS5_PBKDF2_HMAC(pass, strlen(pass), salt, strlen(salt), iterations,
599-
EVP_sha512(), outputBytes, digest);
600-
for (i = 0; i < outputBytes; i++)
601-
sprintf(hexResult + (i * 2), "%02x", 255 & digest[i]);
602-
603-
free(digest);
604-
}
605-
#endif
606-
607587
/**
608588
* Generate a PBKDF2 password hash with the given password and salt.
609589
*
@@ -672,7 +652,12 @@ pbkdf2_hash(const char* password, int password_len, const char* salt,
672652
PKCS5_PBKDF2_HMAC(password, password_len, salt, salt_len, 1000,
673653
EVP_sha512(), digest_len, digest);
674654

675-
for (i = 0; i < digest_len; i++) {
655+
/*
656+
* The -1 here should avoid a buffer overflow as otherwise this will
657+
* get to be exactly the same size as buffer with no room for the
658+
* null.
659+
*/
660+
for (i = 0; i < (digest_len - 1); i++) {
676661
sprintf(buffer + salt_len + 4 + (i * 2), "%02x", 255 & digest[i]);
677662
}
678663

src/player.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ check_password(dbref player, const char *password)
123123
}
124124
}
125125

126-
if (!strcmp(pword, processed))
126+
/*
127+
* There was a bug where the password hash was causing a buffer
128+
* overflow. Some compilers apparently cover this up or smooth
129+
* this over in some fashion which means it is an inconsistent
130+
* overflow.
131+
*
132+
* By matching by the length of 'processed', we'll be able to
133+
* support any old "too long" hashes that may have slipped into
134+
* the system.
135+
*/
136+
if (!strncmp(pword, processed, strlen(processed)))
127137
return 1;
128138

129139
return 0;

0 commit comments

Comments
 (0)