* Fixed server crash with double Primary block in config file.
authorGiovanni Giacobbi <johnny@silcnet.org>
Sat, 11 Jan 2003 17:24:31 +0000 (17:24 +0000)
committerGiovanni Giacobbi <johnny@silcnet.org>
Sat, 11 Jan 2003 17:24:31 +0000 (17:24 +0000)
  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
CREDITS
apps/silcd/serverconfig.c
apps/silcd/serverconfig.h
doc/silcd.conf.yo
lib/silcutil/silcconfig.c
lib/silcutil/silcconfig.h
lib/silcutil/silclog.c
lib/silcutil/silclog.h
scripts/stripspaces.tcl

diff --git a/CHANGES b/CHANGES
index 6120e703240d75185918ec25aaaac782dacbeb81..7f5327182ccd0eae12e9573b3aee6688c6ab0697 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,15 @@
+Sat Jan 11 18:16:29 CET 2003  Giovanni Giacobbi <giovanni@giacobbi.net>
+
+       * 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 <c0ffee@penguin-breeder.org>
 
        * Don't display "foo appears as foo\nYou're now known as foo"
diff --git a/CREDITS b/CREDITS
index 63ec9f6af6d0d2371c902b285477444fe4e77057..950df4ab24aa10282d2339a559a254564637a40c 100644 (file)
--- 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
 
index 911caff0dde735085b13ccc4fa628097740cbe6e..2121264101e7665917e15b7519a0166af7f7642a 100644 (file)
@@ -2,7 +2,7 @@
 
   serverconfig.c
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
   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;
   }
 
index 164647d8262664e3fc4830a6c14f5936c102a327..03cb63a0d89b57304e2508dd961e9216d55c0ecb 100644 (file)
@@ -2,7 +2,7 @@
 
   serverconfig.h
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
   Copyright (C) 1997 - 2002 Pekka Riikonen
 
index 9eab20c4ca3b15e415d6a879847cdfa08d894210..a78ed96437614084655bf2967ccc93290651dc51 100644 (file)
@@ -455,7 +455,8 @@ manpageauthor()
 SILC is designed and written by Pekka Riikonen <priikone@iki.fi> and rest
 of the SILC Project.
 
-Configuration file format and parser is by Johnny Mnemonic.
+Configuration file format and parser is by Giovanni Giacobbi
+<giovanni@giacobbi.net>.
 
 This manpage was written by Mika 'Bostik' Boström <bostik@lut.fi>
 
index 1f3e4699fdf79d20891961d4463f4b507dd69a73..2066f95719ed0531315ffaebdc7bb2e9d8c36346 100644 (file)
@@ -2,9 +2,9 @@
 
   silcconfig.c
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
-  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;
 
index 91225867c716fd5c34a01ba053b39d61a6e6e6de..4d45aa86f1e2f2f37bde8231dd3bbd24dd724715 100644 (file)
@@ -2,9 +2,9 @@
 
   silcconfig.h
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
-  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
index 14d31d545f519ca0caa9e7423b9094fdc7f16393..736edb03f4daa8b671ef8a6183797dfec908b93d 100644 (file)
@@ -2,7 +2,7 @@
 
   silclog.c
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
   Copyright (C) 1997 - 2002 Pekka Riikonen
 
index 60b2f637432af626e5022b72278b9a2be57eac3f..337c882e252fe3067b2ed61a00edb17f198455b4 100644 (file)
@@ -2,7 +2,7 @@
 
   silclog.h
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
   Copyright (C) 1997 - 2002 Pekka Riikonen
 
index 0e629665aed837c2c417d499ce19deb4ec89bec5..01bac3200ce2a6f43996b0c28b7a4f7edf2090cf 100755 (executable)
@@ -2,9 +2,9 @@
 #
 #  stripspaces.tcl - strip trailing spaces from source files
 #
-#  Author: Johnny Mnemonic <johnny@themnemonic.org>
+#  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 #
-#  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