Advertisement
bsddeamon

overflow.c

Jan 14th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Fichier: overflow.c
  3. // Hacker: Samuel Duclos
  4. // License: This program is 3-clause BSD licensed.
  5. // Date: Jeudi, le 14 janvier 2016.
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "MonDallas.h"
  9. #include <stdio.h> // puts(), getchar().
  10. // http://www.keil.com/support/man/docs/c51/c51_puts.htm
  11.  
  12. #include <string.h> // strcpy(), strcmp().
  13. // http://www.keil.com/support/man/docs/c51/c51_strcpy.htm
  14. // http://www.keil.com/support/man/docs/c51/c51_strcmp.htm
  15.  
  16. // J’ai "oublie" mon mot de passe par
  17. // hasard mais on s'en fout…
  18. // const specifie que la valeur est fixe.
  19. const char password[8] = "UNKNOWN";
  20. char buffer2[8]; // <- Buffer trop petit.
  21.  
  22. // Fonction qui se fout de la taille des tampons.
  23. void UARTgetline(char *string);
  24.  
  25. // Fonction qu'on ne "peut pas" acceder.
  26. void system_access(void);
  27.  
  28. // Simule une interruption systeme par
  29. // un element exterieur au programme.
  30. void system_interrupt(void) reentrant;
  31.  
  32. void main(void) {
  33.   SCON0 = 0x50;
  34.   TMOD |= 0x20;
  35.   TH1 = 0xFF;
  36.   PCON = 0x80;
  37.   TR1 = 1;
  38.   TI_0 = 1;
  39.  
  40.   system_interrupt();
  41. }
  42.  
  43. // Prend le input du clavier.
  44. void UARTgetline(char *string) {
  45.   char i = 0;
  46.  
  47.   // Ne verifie pas le nombre de caracteres pris en input.
  48.   do { string[i] = getchar();
  49.   } while (string[i++] != '\n');
  50.  
  51.   // Transforme le buffer en chaine de caracteres.
  52.   string[i] = '\0';
  53. }
  54.  
  55. void system_access(void) {
  56.   while (1) {
  57.     puts("Access granted!");
  58.     puts(buffer2);
  59.   }
  60. }
  61.  
  62. void system_interrupt(void) reentrant {
  63.   char buffer1[32]; // Buffer trop gros.
  64.   while (1) {
  65.     UARTgetline(buffer1);
  66.  
  67.     // Copie buffer1 dans buffer2.
  68.     // Voir documentation (liens en haut).
  69.     strcpy(buffer2, buffer1);
  70.  
  71.     // Compare buffer2 avec password.
  72.     // Retourne 0 s'ils sont egaux.
  73.     if (strcmp(buffer2, password) == 0) {
  74.  
  75.       // Pas suppose se rendre la.
  76.       system_access();
  77.     }
  78.  
  79.     // puts() ne prend pas 1k de memoire
  80.     // pour le programme comme printf().
  81.     puts("Access denied!");
  82.     puts(buffer2);
  83.   }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement