diff options
| author | Eli Zaretskii | 2001-04-09 10:53:42 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2001-04-09 10:53:42 +0000 |
| commit | ceeb3d7db5c33884003f280ddfaa1c50a70cc7ad (patch) | |
| tree | c1fad19f2d0666c16818560895fdb233c3d9f183 /src/gmalloc.c | |
| parent | 9f9a5e7a8c7650f0c45404cb8762c5eabc57ba79 (diff) | |
| download | emacs-ceeb3d7db5c33884003f280ddfaa1c50a70cc7ad.tar.gz emacs-ceeb3d7db5c33884003f280ddfaa1c50a70cc7ad.zip | |
(align): If the argument SIZE would overflow
__malloc_ptrdiff_t, fail right away.
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 751e90baf13..3508304da33 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -437,7 +437,14 @@ align (size) | |||
| 437 | __ptr_t result; | 437 | __ptr_t result; |
| 438 | unsigned long int adj; | 438 | unsigned long int adj; |
| 439 | 439 | ||
| 440 | result = (*__morecore) (size); | 440 | /* align accepts an unsigned argument, but __morecore accepts a |
| 441 | signed one. This could lead to trouble if SIZE overflows a | ||
| 442 | signed int type accepted by __morecore. We just punt in that | ||
| 443 | case, since they are requesting a ludicrous amount anyway. */ | ||
| 444 | if ((__malloc_ptrdiff_t)size < 0) | ||
| 445 | result = 0; | ||
| 446 | else | ||
| 447 | result = (*__morecore) (size); | ||
| 441 | adj = (unsigned long int) ((unsigned long int) ((char *) result - | 448 | adj = (unsigned long int) ((unsigned long int) ((char *) result - |
| 442 | (char *) NULL)) % BLOCKSIZE; | 449 | (char *) NULL)) % BLOCKSIZE; |
| 443 | if (adj != 0) | 450 | if (adj != 0) |