Skip to content

Instantly share code, notes, and snippets.

@mclosson
Last active June 27, 2016 03:17
Show Gist options
  • Save mclosson/09e44bc38c053d166951ca41239973d2 to your computer and use it in GitHub Desktop.
Save mclosson/09e44bc38c053d166951ca41239973d2 to your computer and use it in GitHub Desktop.
/* You can successfully authenticate to this program by entering the password
* as seen in the code below, or by doing something else. What is it and why?
*
* $ make good_enough_password
* $ ./good_enough_password
* Enter password:
*
* Hint: The problem is worse on a 32bit platform. To compile for 32bit on OSX
* $ cc -m32 -o good_enough_password good_enough_password.c
* $ ./good_enough_password
* Enter password:
*
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAXLEN 255
int main(int argc, const char *argv[])
{
char *password = "secret squirrel";
char guess[MAXLEN];
bool authenticated = false;
while (!authenticated) {
printf("Enter password: ");
fgets(guess, MAXLEN, stdin);
if (!strncmp(password, guess, sizeof password)) {
authenticated = true;
printf("Success! You are now authenticated!\n");
}
}
printf("You entered : \"%s\"\n", guess);
printf("The password was: \"%s\"\n", password);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment