Skip to content

Instantly share code, notes, and snippets.

@dreamiurg
Created July 26, 2013 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamiurg/6092734 to your computer and use it in GitHub Desktop.
Save dreamiurg/6092734 to your computer and use it in GitHub Desktop.
$ cat buffer.c
#include <stdio.h>
#include <string.h>
#include <time.h>
int main() {
char src[4] = {0};
char dst[1] = {0};
time_t epoch;
time(&epoch);
int ret = strftime(src, sizeof(src)+1, "%F %r", localtime(&epoch));
printf("%s\n", src);
printf("ret=%d\n", ret);
memcpy(dst, src, sizeof(src));
return 0;
}
$ gcc -o buffer ./buffer.c
$ valgrind ./buffer
==20415== Memcheck, a memory error detector.
==20415== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==20415== Using LibVEX rev 1658, a library for dynamic binary translation.
==20415== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==20415== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==20415== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==20415== For more details, rerun with: -v
==20415==
ret=0
==20415==
==20415== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
==20415== malloc/free: in use at exit: 0 bytes in 0 blocks.
==20415== malloc/free: 10 allocs, 10 frees, 2,497 bytes allocated.
==20415== For counts of detected errors, rerun with: -v
==20415== All heap blocks were freed -- no leaks are possible.
$ gcc -o buffer -fstack-protector-all ./buffer.c
$ ./buffer
ret=0
*** stack smashing detected ***: ./buffer terminated
zsh: abort ./buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment