0020-pidof: Prevent integer overflows with grow_size().
Note: unlike "size" and "omit_size", "path_alloc_size" is not multiplied by "sizeof(struct el)" but the checks in grow_size() allow for a roughly 100MB path_alloc_size, which should be more than enough for readlink().
This commit is contained in:
parent
4abe4a51a0
commit
73008f26ea
8
pidof.c
8
pidof.c
@ -21,6 +21,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
@ -30,7 +31,12 @@
|
|||||||
#include <proc/procps.h>
|
#include <proc/procps.h>
|
||||||
|
|
||||||
|
|
||||||
#define grow_size(x) (x = x * 5 / 4 + 1024)
|
#define grow_size(x) do { \
|
||||||
|
if ((x) < 0 || (size_t)(x) >= INT_MAX / 5 / sizeof(struct el)) \
|
||||||
|
xerrx(EXIT_FAILURE, _("integer overflow")); \
|
||||||
|
(x) = (x) * 5 / 4 + 1024; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define safe_free(x) if (x) { free(x); x=NULL; }
|
#define safe_free(x) if (x) { free(x); x=NULL; }
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user