Last active
August 29, 2015 13:57
-
-
Save hiepnd/9906317 to your computer and use it in GitHub Desktop.
Subtle bug that causes stack corruption on Android (run ok on iOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <openssl/md5.h> | |
string md5_evil(const char *message) { | |
unsigned char digest[MD5_DIGEST_LENGTH]; | |
MD5((unsigned char*)message, strlen(message), digest); | |
char md[2*MD5_DIGEST_LENGTH]; | |
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { | |
sprintf(&md[i*2], "%02x", (unsigned int)digest[i]); | |
} | |
return string(md); | |
} | |
/* FIX */ | |
string md5_angel(const char *message) { | |
unsigned char digest[MD5_DIGEST_LENGTH]; | |
MD5((unsigned char*)message, strlen(message), digest); | |
char md[2*MD5_DIGEST_LENGTH + 1]; | |
md[2*MD5_DIGEST_LENGTH] = '\0'; | |
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { | |
sprintf(&md[i*2], "%02x", (unsigned int)digest[i]); | |
} | |
return string(md); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment