Advertisement
rc-chuah

buffer-overflow

Dec 30th, 2021
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.     int authorized = 0;
  5.     char sys_pass[16] = "secret!";
  6.     char usr_pass[16];
  7.  
  8.     printf("enter password: ");
  9.     scanf("%s", usr_pass);
  10.  
  11.     printf("usr_pass: %s\n", usr_pass);
  12.     printf("sys_pass: %s\n", sys_pass);
  13.     printf("auth val: %d\n", authorized);
  14.     printf("usr_pass   addr: %p\n", (void *)usr_pass);
  15.     printf("sys_pass   addr: %p\n", (void *)sys_pass);
  16.     printf("authorized addr: %p\n", (void *)&authorized);
  17.  
  18.     if (strcmp(sys_pass, usr_pass) == 0) {
  19.         authorized = 1;
  20.     }
  21.  
  22.     if (authorized) {
  23.         printf("password is correct!\n");
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement