From 237f3fb11e474d811ca667b18a45d009633f508f Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Sat, 11 Jan 2003 17:24:31 +0000 Subject: [PATCH] * Fixed server crash with double Primary block in config file. Fixed also various memory leaks around the config file parser. Affected files lib/silcutil/silcconfig.c, silcd/serverconfig.c. * Changed my nickname (Johnny Mnemonic) to my real name, this means that bugs introduced by him were actually introduced by me! --- CHANGES | 12 ++++++++++++ CREDITS | 8 ++++---- apps/silcd/serverconfig.c | 37 ++++++++++++++++++++++++++++++------- apps/silcd/serverconfig.h | 2 +- doc/silcd.conf.yo | 3 ++- lib/silcutil/silcconfig.c | 23 +++++++++++++---------- lib/silcutil/silcconfig.h | 4 ++-- lib/silcutil/silclog.c | 2 +- lib/silcutil/silclog.h | 2 +- scripts/stripspaces.tcl | 4 ++-- 10 files changed, 68 insertions(+), 29 deletions(-) diff --git a/CHANGES b/CHANGES index 6120e703..7f532718 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +Sat Jan 11 18:16:29 CET 2003 Giovanni Giacobbi + + * Fixed server crash with double Primary block in config file. + + Fixed also various memory leaks around the config file + parser. Affected files lib/silcutil/silcconfig.c, + silcd/serverconfig.c. + + * Changed my nickname (Johnny Mnemonic) to my real name, this + means that bugs introduced by him were actually introduced + by me! + Tue Jan 7 21:58:53 CET 2003 Jochen Eisinger * Don't display "foo appears as foo\nYou're now known as foo" diff --git a/CREDITS b/CREDITS index 63ec9f6a..950df4ab 100644 --- a/CREDITS +++ b/CREDITS @@ -33,12 +33,12 @@ S: Skinnarilankatu 28 E 2 S: 53850 Lappeenranta S: Finland -N: Johnny Mnemonic +N: Giovanni Giacobbi +E: giovanni@giacobbi.net E: johnny@themnemonic.org -W: http://www.themnemonic.org/ -P: 1024D/34E2AB40 9AC6 1460 A5D0 4DB7 70D0 5DA5 C17F 50CD 34E2 AB40 +P: 1024D/B2D79FC1 6247 640C 1C90 1EE4 D800 E4E2 2D58 3DF1 B2D7 9FC1 +D: silcconfig, silclog, various patches around D: RPM packages -D: silclog, misc bugfixes S: 35100 Padova S: Italy diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 911caff0..21212641 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -2,7 +2,7 @@ serverconfig.c - Author: Johnny Mnemonic + Author: Giovanni Giacobbi Copyright (C) 1997 - 2002 Pekka Riikonen @@ -495,22 +495,40 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigServerInfoInterface); SilcServerConfigServerInfo *server_info = config->server_info; - /* if there isn't the struct alloc it */ + SERVER_CONFIG_DEBUG(("Received SERVERINFO type=%d name=\"%s\" (val=%x)", + type, name, context)); + + /* if there isn't the main struct alloc it */ if (!server_info) config->server_info = server_info = (SilcServerConfigServerInfo *) silc_calloc(1, sizeof(*server_info)); if (type == SILC_CONFIG_ARG_BLOCK) { if (!strcmp(name, "primary")) { + if (server_info->primary) { + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Double primary specification.")); + got_errno = SILC_CONFIG_EPRINTLINE; + goto got_err; + } CONFIG_IS_DOUBLE(server_info->primary); - if (!tmp) - return SILC_CONFIG_OK; + + /* now check the temporary struct, don't accept empty block and + make sure all fields are there */ + if (!tmp || !tmp->server_ip || !tmp->port) { + got_errno = SILC_CONFIG_EMISSFIELDS; + goto got_err; + } server_info->primary = tmp; config->tmp = NULL; return SILC_CONFIG_OK; } else if (!strcmp(name, "secondary")) { if (!tmp) return SILC_CONFIG_OK; + if (!tmp || !tmp->server_ip || !tmp->port) { + got_errno = SILC_CONFIG_EMISSFIELDS; + goto got_err; + } SILC_SERVER_CONFIG_LIST_APPENDTMP(server_info->secondary); config->tmp = NULL; return SILC_CONFIG_OK; @@ -603,9 +621,13 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) return SILC_CONFIG_OK; got_err: - silc_free(tmp); - silc_free(config->tmp); - config->tmp = NULL; + /* here we need to check if tmp exists because this function handles + * misc data (multiple fields and single-only fields) */ + if (tmp) { + silc_free(tmp->server_ip); + silc_free(tmp); + config->tmp = NULL; + } return got_errno; } @@ -1438,6 +1460,7 @@ SilcServerConfig silc_server_config_alloc(const char *filename) } } silc_server_config_destroy(config_new); + silc_config_close(file); return NULL; } diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index 164647d8..03cb63a0 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -2,7 +2,7 @@ serverconfig.h - Author: Johnny Mnemonic + Author: Giovanni Giacobbi Copyright (C) 1997 - 2002 Pekka Riikonen diff --git a/doc/silcd.conf.yo b/doc/silcd.conf.yo index 9eab20c4..a78ed964 100644 --- a/doc/silcd.conf.yo +++ b/doc/silcd.conf.yo @@ -455,7 +455,8 @@ manpageauthor() SILC is designed and written by Pekka Riikonen and rest of the SILC Project. -Configuration file format and parser is by Johnny Mnemonic. +Configuration file format and parser is by Giovanni Giacobbi +. This manpage was written by Mika 'Bostik' Boström diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index 1f3e4699..2066f957 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -2,9 +2,9 @@ silcconfig.c - Author: Johnny Mnemonic + Author: Giovanni Giacobbi - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 2002 - 2003 Giovanni Giacobbi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -172,7 +172,8 @@ static SilcConfigOption *silc_config_find_option(SilcConfigEntity ent, } return NULL; } -/* ... */ +/* Converts a string in the type specified. returns a dynamically + * allocated pointer. */ static void *silc_config_marshall(SilcConfigType type, const char *val) { void *pt; @@ -578,7 +579,7 @@ static int silc_config_main_internal(SilcConfigEntity ent) } else { void *pt; - int ret; + int ret = 0; /* very important in case of no cb */ if (*(*p)++ != '=') return SILC_CONFIG_EEXPECTEDEQUAL; @@ -594,15 +595,17 @@ static int silc_config_main_internal(SilcConfigEntity ent) pt = silc_config_marshall(thisopt->type, buf); if (!pt) return SILC_CONFIG_EINVALIDTEXT; - if (thisopt->cb) { + if (thisopt->cb) ret = thisopt->cb(thisopt->type, thisopt->name, file->line, pt, thisopt->context); - if (ret) { - SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret)); - return ret; - } - } + + /* since we have to free "pt" both on failure and on success, we + assume that ret == 0 if we didn't actually call any cb. */ silc_free(pt); + if (ret) { + SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret)); + return ret; + } } continue; diff --git a/lib/silcutil/silcconfig.h b/lib/silcutil/silcconfig.h index 91225867..4d45aa86 100644 --- a/lib/silcutil/silcconfig.h +++ b/lib/silcutil/silcconfig.h @@ -2,9 +2,9 @@ silcconfig.h - Author: Johnny Mnemonic + Author: Giovanni Giacobbi - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 2002 - 2003 Giovanni Giacobbi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/lib/silcutil/silclog.c b/lib/silcutil/silclog.c index 14d31d54..736edb03 100644 --- a/lib/silcutil/silclog.c +++ b/lib/silcutil/silclog.c @@ -2,7 +2,7 @@ silclog.c - Author: Johnny Mnemonic + Author: Giovanni Giacobbi Copyright (C) 1997 - 2002 Pekka Riikonen diff --git a/lib/silcutil/silclog.h b/lib/silcutil/silclog.h index 60b2f637..337c882e 100644 --- a/lib/silcutil/silclog.h +++ b/lib/silcutil/silclog.h @@ -2,7 +2,7 @@ silclog.h - Author: Johnny Mnemonic + Author: Giovanni Giacobbi Copyright (C) 1997 - 2002 Pekka Riikonen diff --git a/scripts/stripspaces.tcl b/scripts/stripspaces.tcl index 0e629665..01bac320 100755 --- a/scripts/stripspaces.tcl +++ b/scripts/stripspaces.tcl @@ -2,9 +2,9 @@ # # stripspaces.tcl - strip trailing spaces from source files # -# Author: Johnny Mnemonic +# Author: Giovanni Giacobbi # -# Copyright (C) 2002 Johnny Mnemonic +# Copyright (C) 2002 - 2003 Giovanni Giacobbi # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -- 2.24.0