diff options
| author | manuel <manuel@mausz.at> | 2020-05-19 23:59:38 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-05-19 23:59:38 +0200 |
| commit | 0f0e11b3d64ad562016d5c21dadbce74cc70c5f9 (patch) | |
| tree | 02552111ef549609ace513f08325f4f3c7c2c4ea | |
| parent | f2ef25deb1aa356d41cdd3f6e46d9a68c48bfce0 (diff) | |
| download | qmail-0f0e11b3d64ad562016d5c21dadbce74cc70c5f9.tar.gz qmail-0f0e11b3d64ad562016d5c21dadbce74cc70c5f9.tar.bz2 qmail-0f0e11b3d64ad562016d5c21dadbce74cc70c5f9.zip | |
Make sure to limit max alloc size
see https://www.qualys.com/2020/05/19/cve-2005-1513/remote-code-execution-qmail.txt
| -rw-r--r-- | alloc.c | 5 |
1 files changed, 5 insertions, 0 deletions
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <limits.h> | ||
| 1 | #include "alloc.h" | 2 | #include "alloc.h" |
| 2 | #include "error.h" | 3 | #include "error.h" |
| 3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| @@ -14,6 +15,10 @@ static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ | |||
| 14 | unsigned int n; | 15 | unsigned int n; |
| 15 | { | 16 | { |
| 16 | char *x; | 17 | char *x; |
| 18 | if (n >= (INT_MAX >> 3)) { | ||
| 19 | errno = error_nomem; | ||
| 20 | return 0; | ||
| 21 | } | ||
| 17 | n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ | 22 | n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ |
| 18 | if (n <= avail) { avail -= n; return space + avail; } | 23 | if (n <= avail) { avail -= n; return space + avail; } |
| 19 | x = malloc(n); | 24 | x = malloc(n); |
