2002-12-09 12:30:07 +05:30
|
|
|
#ifndef PROCPS_PROC_ALLOC_H
|
|
|
|
#define PROCPS_PROC_ALLOC_H
|
|
|
|
|
|
|
|
#include "procps.h"
|
|
|
|
|
|
|
|
EXTERN_C_BEGIN
|
|
|
|
|
2017-12-16 11:30:00 +05:30
|
|
|
typedef void (*message_fn)(const char *__restrict, ...) __attribute__((format(printf,1,2)));
|
|
|
|
|
2011-11-16 22:19:02 +05:30
|
|
|
/* change xalloc_err_handler to override the default fprintf(stderr... */
|
|
|
|
extern message_fn xalloc_err_handler;
|
|
|
|
|
proc/alloc.*: Use size_t, not unsigned int.
Otherwise this can truncate sizes on 64-bit platforms, and is one of the
reasons the integer overflows in file2strvec() are exploitable at all.
Also: catch potential integer overflow in xstrdup() (should never
happen, but better safe than sorry), and use memcpy() instead of
strcpy() (faster).
Warnings:
- in glibc, realloc(ptr, 0) is equivalent to free(ptr), but not here,
because of the ++size;
- here, xstrdup() can return NULL (if str is NULL), which goes against
the idea of the xalloc wrappers.
We were tempted to call exit() or xerrx() in those cases, but decided
against it, because it might break things in unexpected places; TODO?
1970-01-01 05:30:00 +05:30
|
|
|
extern void *xcalloc(size_t size) MALLOC;
|
2012-11-02 23:20:50 +05:30
|
|
|
extern void *xmalloc(size_t size) MALLOC;
|
proc/alloc.*: Use size_t, not unsigned int.
Otherwise this can truncate sizes on 64-bit platforms, and is one of the
reasons the integer overflows in file2strvec() are exploitable at all.
Also: catch potential integer overflow in xstrdup() (should never
happen, but better safe than sorry), and use memcpy() instead of
strcpy() (faster).
Warnings:
- in glibc, realloc(ptr, 0) is equivalent to free(ptr), but not here,
because of the ++size;
- here, xstrdup() can return NULL (if str is NULL), which goes against
the idea of the xalloc wrappers.
We were tempted to call exit() or xerrx() in those cases, but decided
against it, because it might break things in unexpected places; TODO?
1970-01-01 05:30:00 +05:30
|
|
|
extern void *xrealloc(void *oldp, size_t size) MALLOC;
|
2011-11-16 22:19:02 +05:30
|
|
|
extern char *xstrdup(const char *str) MALLOC;
|
2002-12-09 12:30:07 +05:30
|
|
|
|
|
|
|
EXTERN_C_END
|
|
|
|
|
|
|
|
#endif
|