From d51b819e549d635c5b0293427fba59d097ad8df2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 20 Jun 2005 17:59:06 -0400 Subject: [PATCH] error_message.c, init_et.c: Segregate error tables registered via add_error_table() and the other dynamic methods from the ones allocated via initialize_xxx_error_table() so that we won't fail even for error tables created using old versions of compile_et. Thanks to Nalin Dahyabhai for this suggested patch. --- lib/et/ChangeLog | 7 +++++++ lib/et/error_message.c | 25 ++++++++++++++----------- lib/et/init_et.c | 6 +++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/et/ChangeLog b/lib/et/ChangeLog index aa4880f8c..72f86873a 100644 --- a/lib/et/ChangeLog +++ b/lib/et/ChangeLog @@ -1,5 +1,12 @@ 2005-06-20 Theodore Ts'o + * error_message.c, init_et.c: Segregate error tables registered + via add_error_table() and the other dynamic methods from + the ones allocated via initialize_xxx_error_table() so + that we won't fail even for error tables created using old + versions of compile_et. Thanks to Nalin Dahyabhai for + this suggested patch. + * et_c.awk: Use a dynamically allocated structure in initialize_xxx_error_table(), to prevent segfaults if an old library calls initialize_xxx_error_table, and another diff --git a/lib/et/error_message.c b/lib/et/error_message.c index 9326308c7..90d63c417 100644 --- a/lib/et/error_message.c +++ b/lib/et/error_message.c @@ -27,6 +27,7 @@ static char buffer[25]; struct et_list * _et_list = (struct et_list *) NULL; +struct et_list * _et_dynamic_list = (struct et_list *) NULL; const char * error_message (errcode_t code) @@ -61,6 +62,14 @@ const char * error_message (errcode_t code) return(et->table->msgs[offset]); } } + for (et = _et_dynamic_list; et; et = et->next) { + if (et->table->base == table_num) { + /* This is the right table */ + if (et->table->n_msgs <= offset) + goto oops; + return(et->table->msgs[offset]); + } + } oops: strcpy (buffer, "Unknown code "); if (table_num) { @@ -88,20 +97,14 @@ oops: */ errcode_t add_error_table(const struct error_table * et) { - struct et_list *el = _et_list; - - while (el) { - if (el->table->base == et->base) - return EEXIST; - el = el->next; - } + struct et_list *el; if (!(el = (struct et_list *) malloc(sizeof(struct et_list)))) return ENOMEM; el->table = et; - el->next = _et_list; - _et_list = el; + el->next = _et_dynamic_list; + _et_dynamic_list = el; return 0; } @@ -111,7 +114,7 @@ errcode_t add_error_table(const struct error_table * et) */ errcode_t remove_error_table(const struct error_table * et) { - struct et_list *el = _et_list; + struct et_list *el = _et_dynamic_list; struct et_list *el2 = 0; while (el) { @@ -119,7 +122,7 @@ errcode_t remove_error_table(const struct error_table * et) if (el2) /* Not the beginning of the list */ el2->next = el->next; else - _et_list = el->next; + _et_dynamic_list = el->next; (void) free(el); return 0; } diff --git a/lib/et/init_et.c b/lib/et/init_et.c index 075d26a88..bf27da11c 100644 --- a/lib/et/init_et.c +++ b/lib/et/init_et.c @@ -29,7 +29,7 @@ struct foobar { struct error_table et; }; -extern struct et_list * _et_list; +extern struct et_list * _et_dynamic_list; int init_error_table(const char * const *msgs, long base, int count) { @@ -46,7 +46,7 @@ int init_error_table(const char * const *msgs, long base, int count) new_et->et.base = base; new_et->et.n_msgs= count; - new_et->etl.next = _et_list; - _et_list = &new_et->etl; + new_et->etl.next = _et_dynamic_list; + _et_dynamic_list = &new_et->etl; return 0; } -- 2.47.3