diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-05 20:52:28 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-05 20:52:28 +0000 |
commit | e6d7f2bf28c8575f152f2be9088bdf919c6d1bd1 (patch) | |
tree | 011b8569e906320020188c89b866804e26407c73 | |
parent | 84e0d42775060101744111a75a5ed2090a4f2df9 (diff) |
Don't allow alloc() and aresize() to fail. Their return value was
only checked in two place (both in conjunction with str_save). Upon
malloc/realloc failure we call internal_errorf() which pops throws
and error and pops back to the last good state. OK deraadt@ pval@ fgs@
Original problem noted by mickey@
-rw-r--r-- | bin/ksh/alloc.c | 23 | ||||
-rw-r--r-- | bin/ksh/misc.c | 4 | ||||
-rw-r--r-- | bin/ksh/var.c | 5 |
3 files changed, 15 insertions, 17 deletions
diff --git a/bin/ksh/alloc.c b/bin/ksh/alloc.c index 19f9e86c2b7..09df76b0779 100644 --- a/bin/ksh/alloc.c +++ b/bin/ksh/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.5 2002/03/01 13:06:18 espie Exp $ */ +/* $OpenBSD: alloc.c,v 1.6 2003/08/05 20:52:27 millert Exp $ */ /* * Copyright (c) 2002 Marc Espie. * @@ -63,8 +63,8 @@ alloc(size_t size, Area *ap) struct link *l; l = malloc(size + sizeof(struct link)); - if (!l) - return NULL; + if (l == NULL) + internal_errorf(1, "unable to allocate memory"); l->next = ap->freelist; l->prev = NULL; if (ap->freelist) @@ -87,14 +87,15 @@ aresize(void *ptr, size_t size, Area *ap) lnext = l->next; l2 = realloc(l, size+sizeof(struct link)); - if (l2) { - if (lprev) - lprev->next = l2; - else - ap->freelist = l2; - if (lnext) - lnext->prev = l2; - } + if (l2 == NULL) + internal_errorf(1, "unable to allocate memory"); + if (lprev) + lprev->next = l2; + else + ap->freelist = l2; + if (lnext) + lnext->prev = l2; + return L2P(l2); } diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index dbbc22268e0..688c5820eed 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.16 2003/04/16 23:11:52 tdeval Exp $ */ +/* $OpenBSD: misc.c,v 1.17 2003/08/05 20:52:27 millert Exp $ */ /* * Miscellaneous functions @@ -90,8 +90,6 @@ str_save(s, ap) return NULL; len = strlen(s)+1; p = alloc(len, ap); - if (!p) - return NULL; strlcpy(p, s, len+1); return (p); } diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 400e4f629b3..8d3eacb37d2 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.15 2003/06/26 00:09:45 deraadt Exp $ */ +/* $OpenBSD: var.c,v 1.16 2003/08/05 20:52:27 millert Exp $ */ #include "sh.h" #include "ksh_time.h" @@ -385,8 +385,7 @@ setstr(vq, s, error_ok) export(vq, s); else { vq->val.s = str_save(s, vq->areap); - if (vq->val.s) /* <sjg> don't lie */ - vq->flag |= ALLOC; + vq->flag |= ALLOC; } } else /* integer dest */ if (!v_evaluate(vq, s, error_ok)) |