Skip to content

Instantly share code, notes, and snippets.

@thesp0nge
Last active January 4, 2016 02:39
Show Gist options
  • Select an option

  • Save thesp0nge/8556620 to your computer and use it in GitHub Desktop.

Select an option

Save thesp0nge/8556620 to your computer and use it in GitHub Desktop.
Is a functional bug a security issue?
#include <stdio.h>
#include <stdlib.h>
void do_something_with_it(char *c) {
strncpy(c, "antani", 4095);
return;
}
int main(int argc, char **argv) {
// my specs would require I process 1000 entries, instead I introduce a bug processing just 999
for (int i=1; i<1000; i++) {
c = malloc(4096*sizeof(char);
do_something_with_it(c);
free(c);
}
// as variant, you can consider to mispell the for cycle the other side, missing the <= sign.
for (int i=0; i<999; i++) {
c = malloc(4096*sizeof(char);
do_something_with_it(c);
free(c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment