From 6b06d8ff06b137b0f719eec539bb2234c6cfd479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Mon, 17 Nov 2003 15:39:48 +0100 Subject: [PATCH] Added more paranoia before accepting dumped bytecode. Rev: src/encode.c:1.200 Rev: src/opcodes.c:1.159 Rev: src/opcodes.h:1.37 Rev: src/version.h:1.345 --- src/encode.c | 22 ++++++++++++++++++++-- src/opcodes.c | 11 +++++++++-- src/opcodes.h | 5 ++++- src/version.h | 4 ++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/encode.c b/src/encode.c index a4531c443d..104d651ba2 100644 --- a/src/encode.c +++ b/src/encode.c @@ -2,7 +2,7 @@ || 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.199 2003/11/15 17:25:05 mast Exp $ +|| $Id: encode.c,v 1.200 2003/11/17 14:39:47 grubba Exp $ */ #include "global.h" @@ -29,8 +29,9 @@ #include "bignum.h" #include "pikecode.h" #include "pike_types.h" +#include "opcodes.h" -RCSID("$Id: encode.c,v 1.199 2003/11/15 17:25:05 mast Exp $"); +RCSID("$Id: encode.c,v 1.200 2003/11/17 14:39:47 grubba Exp $"); /* #define ENCODE_DEBUG */ @@ -1193,6 +1194,11 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc */ code_number(PIKE_BYTECODE_METHOD, data); +#ifdef PIKE_USE_MACHINE_CODE + /* Add the checksum of the instrs array. */ + code_number(instrs_checksum, data); +#endif /* PIKE_USE_MACHINE_CODE */ + /* program */ #ifdef ENCODE_PROGRAM #ifdef PIKE_DEBUG @@ -3359,6 +3365,18 @@ static void decode_value2(struct decode_data *data) Pike_error("Unsupported byte-code method: %d\n", bytecode_method); } +#ifdef PIKE_USE_MACHINE_CODE + { + size_t csum; + /* Check the checksum of the instrs array. */ + decode_number(csum, data); + if (csum != instrs_checksum) { + Pike_error("Bad instruction checksum: %d (expected %d)\n", + csum, instrs_checksum); + } + } +#endif /* PIKE_USE_MACHINE_CODE */ + /* Decode program */ if (data->ptr + (int)local_num_program >= data->len) { Pike_error("Failed to decode program. (string too short)\n"); diff --git a/src/opcodes.c b/src/opcodes.c index c7dc882b38..749ccb96c9 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -2,11 +2,11 @@ || 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: opcodes.c,v 1.158 2003/11/15 16:40:04 grubba Exp $ +|| $Id: opcodes.c,v 1.159 2003/11/17 14:39:47 grubba Exp $ */ #include "global.h" -RCSID("$Id: opcodes.c,v 1.158 2003/11/15 16:40:04 grubba Exp $"); +RCSID("$Id: opcodes.c,v 1.159 2003/11/17 14:39:47 grubba Exp $"); #include "constants.h" #include "interpret.h" #include "opcodes.h" @@ -292,6 +292,9 @@ struct keyword instr_names[]= }; struct instr instrs[F_MAX_INSTR - F_OFFSET]; +#ifdef PIKE_USE_MACHINE_CODE +size_t instrs_checksum; +#endif /* PIKE_USE_MACHINE_CODE */ char *low_get_f_name(int n, struct program *p) { @@ -397,6 +400,10 @@ void init_opcodes(void) #endif } +#ifdef PIKE_USE_MACHINE_CODE + instrs_checksum = hash_mem(instrs, sizeof(instrs), sizeof(instrs)); +#endif /* PIKE_USE_MACHINE_CODE */ + #ifdef PIKE_DEBUG for(i=1; i<F_MAX_OPCODE-F_OFFSET;i++) { diff --git a/src/opcodes.h b/src/opcodes.h index e5bea8a2d0..c4cf51d5c0 100644 --- a/src/opcodes.h +++ b/src/opcodes.h @@ -2,7 +2,7 @@ || 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: opcodes.h,v 1.36 2003/11/14 10:12:29 mast Exp $ +|| $Id: opcodes.h,v 1.37 2003/11/17 14:39:48 grubba Exp $ */ #ifndef OPCODES_H @@ -124,6 +124,9 @@ struct hash_table; #endif extern struct instr instrs[]; +#ifdef PIKE_USE_MACHINE_CODE +extern size_t instrs_checksum; +#endif /* PIKE_USE_MACHINE_CODE */ /* Opcode enum */ diff --git a/src/version.h b/src/version.h index f25fb7507c..d5c20d75b4 100644 --- a/src/version.h +++ b/src/version.h @@ -2,12 +2,12 @@ || 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: version.h,v 1.344 2003/09/05 15:19:49 mast Exp $ +|| $Id: version.h,v 1.345 2003/11/17 14:39:47 grubba Exp $ */ #define PIKE_MAJOR_VERSION 7 #define PIKE_MINOR_VERSION 5 -#define PIKE_BUILD_VERSION 12 +#define PIKE_BUILD_VERSION 13 /* Prototypes begin here */ void f_version(INT32 args); -- GitLab