From 99c3c059961e9abdf76b92e9ab22fe26b929ec20 Mon Sep 17 00:00:00 2001 From: hunt Date: Mon, 19 Mar 2007 03:00:56 +0000 Subject: [PATCH] 2007-03-18 Martin Hunt * staprun.h (err): Define. * symbols.c (get_sections): More overflow checking. --- runtime/staprun/ChangeLog | 4 ++++ runtime/staprun/staprun.h | 2 ++ runtime/staprun/symbols.c | 19 ++++++++++++++----- runtime/sym.c | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog index 899e1269b..c55e88504 100644 --- a/runtime/staprun/ChangeLog +++ b/runtime/staprun/ChangeLog @@ -1,4 +1,8 @@ 2007-03-18 Martin Hunt + * staprun.h (err): Define. + * symbols.c (get_sections): More overflow checking. + +2007-03-18 Martin Hunt * symbols.c (get_sections): Filter out .gnu.linkonce.* sections except for .gnu.linkonce.this_module. diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h index 7a3fd00cf..57a78809f 100644 --- a/runtime/staprun/staprun.h +++ b/runtime/staprun/staprun.h @@ -40,6 +40,8 @@ #define dbug(args...) ; #endif /* DEBUG */ +#define err(args...) {fprintf(stderr,"%s:%d ",__FUNCTION__, __LINE__); fprintf(stderr,args); } + /* we define this so we are compatible with old transport, but we don't have to use it. */ #define STP_OLD_TRANSPORT #include "../transport/transport_msgs.h" diff --git a/runtime/staprun/symbols.c b/runtime/staprun/symbols.c index ce4359292..ca18a8cae 100644 --- a/runtime/staprun/symbols.c +++ b/runtime/staprun/symbols.c @@ -78,12 +78,16 @@ static int get_sections(char *name, char *data_start, int datalen) /* create next section */ sec = (struct _stp_symbol *)data; + if (data - data_start + (int)sizeof(struct _stp_symbol) > datalen) + goto err1; data += sizeof(struct _stp_symbol); sec->addr = strtoul(buf,NULL,16); sec->symbol = (char *)(strdata - strdata_start); mod->num_sections++; /* now create string data for the section */ + if (strdata - strdata_start + strlen(strdata) >= sizeof(strdata_start)) + goto err1; strcpy(strdata, secname); strdata += strlen(secname) + 1; @@ -102,16 +106,21 @@ static int get_sections(char *name, char *data_start, int datalen) /* consolidate buffers */ len = strdata - strdata_start; - if ((len + data - data_start) > datalen) { - fprintf(stderr, "ERROR: overflowed buffers in get_sections. Size needed = %d\n", - (int)(len + data - data_start)); - cleanup_and_exit(0); - } + if ((len + data - data_start) > datalen) + goto err0; strdata = strdata_start; while (len--) *data++ = *strdata++; return data - data_start; + +err1: + close(fd); + closedir(secdir); +err0: + err("overflowed buffers.\n"); + cleanup_and_exit(0); + return 0; /* not reached */ } #undef SECDIR diff --git a/runtime/sym.c b/runtime/sym.c index 1a18f95bb..a5bc01954 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -25,7 +25,7 @@ static unsigned long _stp_module_relocate (const char *module, const char *secti static struct _stp_symbol *last_sec; unsigned long flags; int i,j; - printk("_stp_relocate_module: %s, %s, %lx\n", module, section, offset); + dbug("_stp_relocate_module: %s, %s, %lx\n", module, section, offset); STP_LOCK_MODULES; if (! module || _stp_num_modules == 0) { STP_UNLOCK_MODULES; -- 2.43.5