mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-10 14:02:33 +02:00
MINOR: tools: provide a may_access() function and make dump_hex() use it
It's a bit too easy to crash by accident when using dump_hex() on any area. Let's have a function to check if the memory may safely be read first. This one abuses the stat() syscall checking if it returns EFAULT or not, in which case it means we're not allowed to read from there. In other situations it may return other codes or even a success if the area pointed to by the file exists. It's important not to abuse it though and as such it's tested only once per output line.
This commit is contained in:
@@ -1423,7 +1423,8 @@ int dump_text(struct buffer *out, const char *buf, int bsize);
|
||||
int dump_binary(struct buffer *out, const char *buf, int bsize);
|
||||
int dump_text_line(struct buffer *out, const char *buf, int bsize, int len,
|
||||
int *line, int ptr);
|
||||
void dump_hex(struct buffer *out, const char *pfx, const void *buf, int len);
|
||||
void dump_hex(struct buffer *out, const char *pfx, const void *buf, int len, int unsafe);
|
||||
int may_access(const void *ptr);
|
||||
|
||||
/* same as realloc() except that ptr is also freed upon failure */
|
||||
static inline void *my_realloc2(void *ptr, size_t size)
|
||||
|
||||
Reference in New Issue
Block a user