Advertisement
johnmudd

_chk stubs

Jun 9th, 2015
246
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdarg.h>
  4.  
  5. #define VA_WRAP(exp) \
  6.     va_list va; \
  7.     int done; \
  8.     va_start(va, format); \
  9.     done = exp; \
  10.     va_end(va); \
  11.     return done;
  12.  
  13. void* __memcpy_chk(void* dest, const void* src, size_t copy_amount, size_t dest_len) {
  14.     return memcpy(dest, src, copy_amount);
  15. }
  16.  
  17. int __sprintf_chk( char *dest, int flags, size_t dest_len_from_compiler, const char *format, ...) {
  18.     VA_WRAP( vsprintf(dest, format, va) )
  19. }
  20.  
  21. char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size) {
  22.     return strcat(dest, src);
  23. }
  24.  
  25. void* __memmove_chk (void* dest, const void* src, size_t len, size_t dest_len) {
  26.     return memmove(dest, src, len);
  27. }
  28.  
  29. int __fprintf_chk (FILE *fp, int flag, const char *format, ...) {
  30.     VA_WRAP( vfprintf (fp, format, va) )
  31. }
  32.  
  33. char *__strcpy_chk (char *dest, const char *src, size_t dest_len) {
  34.     return strcpy(dest, src);
  35. }
  36.  
  37. int __vfprintf_chk (FILE *stream, int flags, const char *format, va_list va) {
  38.     return vfprintf(stream, format, va);
  39. }
  40.  
  41. char* __stpcpy_chk(char* dest, const char* src, size_t dest_len) {
  42.     return stpcpy(dest, src);
  43. }
  44.  
  45. int __printf_chk (int flag, const char *format, ...) {
  46.     VA_WRAP( vfprintf (stdout, format, va) )
  47. }
  48.  
  49. int __vsprintf_chk( char *dest, int flags, size_t dest_len_from_compiler, const char *format, va_list va) {
  50.     return vsnprintf(dest, dest_len_from_compiler, format, va);
  51. }  
  52.  
  53. int __vsnprintf_chk( char *dest, size_t supplied_size, int flags, size_t dest_len_from_compiler, const char *format, va_list va) {
  54.     return vsnprintf(dest, supplied_size, format, va);
  55. }  
  56.  
  57. void* __memset_chk (void* dest, int c, size_t n, size_t dest_len) {
  58.     return memset(dest, c, n);
  59. }  
  60.  
  61. int __snprintf_chk( char *dest, size_t supplied_size, int flags, size_t dest_len_from_compiler, const char *format, ...) {
  62.     VA_WRAP( __vsnprintf_chk(dest, supplied_size, flags, dest_len_from_compiler, format, va) )
  63. }
  64.  
  65. int __open64_2 (const char *file, int oflag)
  66. {
  67.     printf("%s[%d]: Not implemented.\n", __FILE__, __LINE__);
  68.     return 0;
  69. }
Advertisement
RAW Paste Data Copied
Advertisement