Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langc
char* name; /* initialized externally */
char filename[128];
sprintf(filename, "%s.txt", name);
/* open filename * /

However, since because the sprintf() function makes no guarantees regarding the length of the string generated, a sufficiently-long string in name could generate a buffer overflow.

...

Code Block
bgColor#ccccff
langc
char* name; /* initialized externally */
char filename[128];
snprintf(filename, sizeof( filename), "%s.txt", name);
/* open filename * /

...