Branch: Tag:

2007-01-16

2007-01-16 18:31:18 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed NULL dereference at out of memory in low_start_new_program().
Found by Klocwork.

Rev: src/program.c:1.612

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: program.c,v 1.611 2007/01/16 18:22:41 grubba Exp $ + || $Id: program.c,v 1.612 2007/01/16 18:31:18 grubba Exp $   */      #include "global.h"
2288:    Pike_compiler->fake_object=alloc_object();      #ifdef PIKE_DEBUG -  Pike_compiler->fake_object->storage=(char *)xalloc(256 * sizeof(struct svalue)); +  Pike_compiler->fake_object->storage=(char *)malloc(256 * sizeof(struct svalue)); +  if (Pike_compiler->fake_object->storage) {    /* Stipple to find illegal accesses */    MEMSET(Pike_compiler->fake_object->storage,0x55,256*sizeof(struct svalue)); -  +  }   #else    Pike_compiler->fake_object->storage=(char *)malloc(sizeof(struct parent_info));   #endif -  +  if (!Pike_compiler->fake_object->storage) { +  yyerror("Out of memory when allocating object storage."); +  }    /* Can't use GC_ALLOC on fake objects, but still it's good to know    * that they never take over a stale gc marker. */    if (Pike_in_gc) remove_marker(Pike_compiler->fake_object);
2316:    debug_malloc_touch(Pike_compiler->fake_object);    debug_malloc_touch(Pike_compiler->fake_object->storage);    +  if (Pike_compiler->fake_object->storage) {    if(name)    {    /* Fake objects have parents regardless of PROGRAM_USE_PARENT */
2326:    ((struct parent_info *)Pike_compiler->fake_object->storage)->parent=0;    ((struct parent_info *)Pike_compiler->fake_object->storage)->parent_identifier=0;    } +  }       Pike_compiler->new_program=p;