Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for buffer overflow issue #728 #729

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions src/fbmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,26 +584,6 @@ rnd(void *buffer)
*
*********************************************************************/

#ifdef USE_SSL
static void
PBKDF2_HMAC_SHA_512(const char* pass, const unsigned char* salt,
int32_t iterations, uint32_t outputBytes,
char* hexResult)
{
unsigned int i;
unsigned char* digest;

digest = (unsigned char*)malloc(outputBytes);

PKCS5_PBKDF2_HMAC(pass, strlen(pass), salt, strlen(salt), iterations,
EVP_sha512(), outputBytes, digest);
for (i = 0; i < outputBytes; i++)
sprintf(hexResult + (i * 2), "%02x", 255 & digest[i]);

free(digest);
}
#endif

/**
* Generate a PBKDF2 password hash with the given password and salt.
*
Expand Down Expand Up @@ -672,7 +652,12 @@ pbkdf2_hash(const char* password, int password_len, const char* salt,
PKCS5_PBKDF2_HMAC(password, password_len, salt, salt_len, 1000,
EVP_sha512(), digest_len, digest);

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

Expand Down
12 changes: 11 additions & 1 deletion src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ check_password(dbref player, const char *password)
}
}

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

return 0;
Expand Down
Loading