pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:1:   /*   || 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: encode.c,v 1.189 2005/05/31 15:33:38 mast Exp $ + || $Id: encode.c,v 1.190 2008/02/06 19:17:14 mast Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "mapping.h"
pike.git/src/encode.c:25:   #include "fsort.h"   #include "threads.h"   #include "stuff.h"   #include "version.h"   #include "bignum.h"   #include "pikecode.h"   #include "pike_types.h"   #include "opcodes.h"   #include "peep.h"    - RCSID("$Id: encode.c,v 1.189 2005/05/31 15:33:38 mast Exp $"); + RCSID("$Id: encode.c,v 1.190 2008/02/06 19:17:14 mast Exp $");      /* #define ENCODE_DEBUG */      /* Use the old encoding method for programs. */   /* #define OLD_PIKE_ENCODE_PROGRAM */      #ifdef ENCODE_DEBUG   /* Pass a nonzero integer as the third arg to encode_value,    * encode_value_canonic and decode_value to activate this debug. */   #define EDB(N,X) do { debug_malloc_touch(data); if (data->debug>=N) {X;} } while (0)
pike.git/src/encode.c:1900:    { \    case 1: for(e=0;e<num;e++) STR1(S)[e]=ntohs(STR1(S)[e]); break; \    case 2: for(e=0;e<num;e++) STR2(S)[e]=ntohl(STR2(S)[e]); break; \    }   #endif      #define get_string_data(STR,LEN, data) do { \    if((LEN) == -1) \    { \    INT32 what, e, num, numh; \ +  ptrdiff_t sz; \    DECODE("get_string_data"); \    what &= TAG_MASK; \ -  if(data->ptr + num > data->len || num <0) \ -  Pike_error("Failed to decode string. (string range error)\n"); \ +     if(what<0 || what>2) \ -  Pike_error("Failed to decode string. (Illegal size shift)\n"); \ -  STR=begin_wide_shared_string(num, what); \ -  MEMCPY(STR->str, data->data + data->ptr, num << what); \ -  data->ptr+=(num << what); \ +  Pike_error ("Failed to decode string: Illegal size shift %d.\n", \ +  what); \ +  sz = (ptrdiff_t) num << what; \ +  if (sz < 0) \ +  Pike_error ("Failed to decode string: Illegal negative size " \ +  "%"PRINTPTRDIFFT"d.\n", sz); \ +  if (sz > data->len - data->ptr) \ +  Pike_error ("Failed to decode string: Too large size %"PRINTPTRDIFFT"d " \ +  "(max is %"PRINTPTRDIFFT"d).\n", \ +  sz, data->len - data->ptr); \ +  STR=begin_wide_shared_string(num, what); \ +  MEMCPY(STR->str, data->data + data->ptr, sz); \ +  data->ptr += sz; \    BITFLIP(STR); \    STR=end_shared_string(STR); \    }else{ \ -  if(data->ptr + (LEN) > data->len || (LEN) <0) \ -  Pike_error("Failed to decode string. (string range error)\n"); \ -  STR=make_shared_binary_string((char *)(data->data + data->ptr), (LEN)); \ -  data->ptr+=(LEN); \ +  ptrdiff_t sz = (LEN); \ +  if (sz < 0) \ +  Pike_error ("Failed to decode string: Illegal negative size " \ +  "%"PRINTPTRDIFFT"d.\n", sz); \ +  if (sz > data->len - data->ptr) \ +  Pike_error ("Failed to decode string: Too large size %"PRINTPTRDIFFT"d " \ +  "(max is %"PRINTPTRDIFFT"d).\n", \ +  sz, data->len - data->ptr); \ +  STR=make_shared_binary_string((char *)(data->data + data->ptr), sz); \ +  data->ptr += sz; \    } \   }while(0)      #define getdata(X) do { \    long length; \    decode_entry(TAG_STRING, length,data); \    if(data->pass == 1) \    get_string_data(X, length, data); \    else \    data->ptr+=length; \