more careful about disabling cookies
This commit is contained in:
37
aalloc.c
37
aalloc.c
@ -1,6 +1,6 @@
|
|||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.13 2008/11/12 06:05:54 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.14 2008/11/12 06:10:51 tg Exp $");
|
||||||
|
|
||||||
/* mksh integration of aalloc */
|
/* mksh integration of aalloc */
|
||||||
|
|
||||||
@ -69,7 +69,9 @@ struct TArea {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static TCookie gcookie;
|
static TCookie gcookie;
|
||||||
static TCookie gcookie_;
|
#ifdef AALLOC_NO_COOKIES
|
||||||
|
static TCookie fake_cookie;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef AALLOC_TRACK
|
#ifdef AALLOC_TRACK
|
||||||
static PArea track;
|
static PArea track;
|
||||||
@ -152,14 +154,17 @@ anew(void)
|
|||||||
(unsigned long)sizeof (struct TBlock));
|
(unsigned long)sizeof (struct TBlock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!gcookie_) {
|
#ifdef AALLOC_NO_COOKIES
|
||||||
|
#define gcookie fake_cookie
|
||||||
|
#endif
|
||||||
|
if (!gcookie) {
|
||||||
size_t v;
|
size_t v;
|
||||||
|
|
||||||
/* ensure unaligned cookie */
|
/* ensure unaligned cookie */
|
||||||
do {
|
do {
|
||||||
gcookie_ = AALLOC_RANDOM();
|
gcookie = AALLOC_RANDOM();
|
||||||
v = AALLOC_RANDOM() & 7;
|
v = AALLOC_RANDOM() & 7;
|
||||||
} while (!(gcookie_ & PVMASK) || !v);
|
} while (!(gcookie & PVMASK) || !v);
|
||||||
/* randomise seed afterwards */
|
/* randomise seed afterwards */
|
||||||
while (v--)
|
while (v--)
|
||||||
AALLOC_RANDOM();
|
AALLOC_RANDOM();
|
||||||
@ -167,14 +172,18 @@ anew(void)
|
|||||||
atexit(track_check);
|
atexit(track_check);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#undef gcookie
|
||||||
|
|
||||||
ap = NULL; safe_realloc(ap, sizeof (struct TArea));
|
ap = NULL; safe_realloc(ap, sizeof (struct TArea));
|
||||||
bp = NULL; safe_realloc(bp, AALLOC_INITSZ);
|
bp = NULL; safe_realloc(bp, AALLOC_INITSZ);
|
||||||
/* ensure unaligned cookie */
|
/* ensure unaligned cookie */
|
||||||
|
#ifdef AALLOC_NO_COOKIES
|
||||||
bp->cookie = 0;
|
bp->cookie = 0;
|
||||||
// do {
|
#else
|
||||||
// bp->cookie = AALLOC_RANDOM();
|
do {
|
||||||
// } while (!(bp->cookie & PVMASK));
|
bp->cookie = AALLOC_RANDOM();
|
||||||
|
} while (!(bp->cookie & PVMASK));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* first byte after block */
|
/* first byte after block */
|
||||||
bp->endp = (char *)bp + AALLOC_INITSZ; /* bp + size of the block */
|
bp->endp = (char *)bp + AALLOC_INITSZ; /* bp + size of the block */
|
||||||
@ -253,7 +262,11 @@ track_check(void)
|
|||||||
ap = track;
|
ap = track;
|
||||||
ap->ocookie ^= gcookie;
|
ap->ocookie ^= gcookie;
|
||||||
ap->prev.iv ^= gcookie;
|
ap->prev.iv ^= gcookie;
|
||||||
if ((ap->prev.iv & PVMASK) || !ap->ocookie) {
|
if ((ap->prev.iv & PVMASK)
|
||||||
|
#ifndef AALLOC_NO_COOKIES
|
||||||
|
|| !(ap->ocookie & PVMASK)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
/* buffer overflow or something? */
|
/* buffer overflow or something? */
|
||||||
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
||||||
" %p, %p, %p; exiting", ap, ap->prev.pv,
|
" %p, %p, %p; exiting", ap, ap->prev.pv,
|
||||||
@ -318,7 +331,11 @@ adelete(PArea *pap)
|
|||||||
while (tp) {
|
while (tp) {
|
||||||
TPtr lp;
|
TPtr lp;
|
||||||
lp.iv = tp->prev.iv ^ gcookie;
|
lp.iv = tp->prev.iv ^ gcookie;
|
||||||
if ((lp.iv & PVMASK) || !tp->ocookie) {
|
if ((lp.iv & PVMASK)
|
||||||
|
#ifndef AALLOC_NO_COOKIES
|
||||||
|
|| !(tp->ocookie & PVMASK)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
AALLOC_WARN("AALLOC_TRACK data structure %p destroyed:"
|
||||||
" %p, %p, %p", tp, tp->prev.pv, tp->bp.pv,
|
" %p, %p, %p", tp, tp->prev.pv, tp->bp.pv,
|
||||||
(void *)tp->ocookie);
|
(void *)tp->ocookie);
|
||||||
|
Reference in New Issue
Block a user