mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Add lots of checks for out of memory (re: 0ce0b671
)
Huge typeset -L/-R adjustment length values were still causing crashses on sytems with not enough memory. They should error out gracefully instead of crashing. This commit adds out of memory checks to all malloc/calloc/realloc calls that didn't have them (which is all but two or three). The stkalloc/stakalloc calls don't need the checks; it has automatic checking, which is done by passing a pointer to the outofspace() function to the stakinstall() call in init.c. src/lib/libast/include/error.h: - Change the ERROR_PANIC exit status value from ERROR_LEVEL (255) to 77, which is what it is supposed to be according to the libast error.3 manual page. Exit statuses > 128 for anything else than signals are not POSIX compliant and may cause misbehaviour. src/cmd/ksh93/include/defs.h, src/cmd/ksh93/sh/init.c: - To facilitate consistency, add a simple extern sh_outofmemory() function that throws an ERROR_PANIC "out of memory". src/cmd/ksh93/include/shell.h, src/cmd/ksh93/data/builtins.c: - Remove now-redundant e_nospace[] extern message; it is now only used in one place so it might as well be a string literal in sh_outofmemory(). All other changed files: - Verify the result of all malloc/calloc/realloc calls and call sh_outofmemory() if they fail.
This commit is contained in:
parent
0ce0b67149
commit
18529b88c6
28 changed files with 138 additions and 14 deletions
|
@ -422,6 +422,8 @@ int sh_iovalidfd(Shell_t *shp, int fd)
|
|||
n = max;
|
||||
max = shp->gd->lim.open_max;
|
||||
shp->sftable = (Sfio_t**)calloc((n+1)*(sizeof(int*)+sizeof(Sfio_t*)+1),1);
|
||||
if(!shp->sftable)
|
||||
sh_outofmemory();
|
||||
if(max)
|
||||
memcpy(shp->sftable,sftable,max*sizeof(Sfio_t*));
|
||||
shp->fdptrs = (int**)(&shp->sftable[n]);
|
||||
|
@ -469,6 +471,8 @@ void sh_ioinit(Shell_t *shp)
|
|||
{
|
||||
filemapsize = 8;
|
||||
filemap = (struct fdsave*)malloc(filemapsize*sizeof(struct fdsave));
|
||||
if(!filemap)
|
||||
sh_outofmemory();
|
||||
sh_iovalidfd(shp,16);
|
||||
shp->sftable[0] = sfstdin;
|
||||
shp->sftable[1] = sfstdout;
|
||||
|
@ -480,6 +484,8 @@ void sh_ioinit(Shell_t *shp)
|
|||
shp->outpool = sfopen(NIL(Sfio_t*),NIL(char*),"sw"); /* pool identifier */
|
||||
shp->outbuff = (char*)malloc(IOBSIZE+4);
|
||||
shp->errbuff = (char*)malloc(IOBSIZE/4);
|
||||
if(!shp->outbuff || !shp->errbuff)
|
||||
sh_outofmemory();
|
||||
sfsetbuf(sfstderr,shp->errbuff,IOBSIZE/4);
|
||||
sfsetbuf(sfstdout,shp->outbuff,IOBSIZE);
|
||||
sfpool(sfstdout,shp->outpool,SF_WRITE);
|
||||
|
@ -1576,6 +1582,8 @@ static int io_heredoc(Shell_t *shp,register struct ionod *iop, const char *name,
|
|||
if(sffileno(tmp)>0)
|
||||
{
|
||||
sfsetbuf(tmp,malloc(IOBSIZE+1),IOBSIZE);
|
||||
if(!tmp)
|
||||
sh_outofmemory();
|
||||
sfset(tmp,SF_MALLOC,1);
|
||||
}
|
||||
sfseek(shp->heredocs,off,SEEK_SET);
|
||||
|
@ -1640,7 +1648,7 @@ void sh_iosave(Shell_t *shp, register int origfd, int oldtop, char *name)
|
|||
long moved;
|
||||
filemapsize += 8;
|
||||
if(!(filemap = (struct fdsave*)realloc(filemap,filemapsize*sizeof(struct fdsave))))
|
||||
errormsg(SH_DICT,ERROR_exit(4),e_nospace);
|
||||
sh_outofmemory();
|
||||
if(moved = (char*)filemap - oldptr)
|
||||
{
|
||||
for(savefd=shp->gd->lim.open_max; --savefd>=0; )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue