Fix memory leaks from ircd_crypt and epoll support.
authorMichael Poole <mdpoole@troilus.org>
Sun, 7 Nov 2004 21:04:59 +0000 (21:04 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 7 Nov 2004 21:04:59 +0000 (21:04 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1264 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/ircd_crypt.h
ircd/engine_epoll.c
ircd/ircd_crypt.c
ircd/ircd_crypt_smd5.c
ircd/m_oper.c

index 4c477827d43cef10a1600e4a00ea7c48bd9e8efe..1e0431976f7708218d7f56dcc96a9ceeaff1dee8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-11-07  Michael Poole <mdpoole@troilus.org>
+
+       * include/ircd_crypt.h (ircd_crypt): This should return char*, not
+       const char*, since it does not own the returned pointer.
+
+       * ircd/ircd_crypt.c (ircd_crypt): Change return type.
+
+       * ircd/ircd_crypt_smd5.c (irc_crypt_smd5): Make passwd a static
+       field since it is returned but this function must own the buffer.
+
+       * ircd/m_oper.c (oper_password_match): Free the string returned by
+       ircd_crypt().
+
+       * ircd/engine_epoll.c (engine_loop): Fix a memory leak.
+
 2004-11-07  Michael Poole <mdpoole@troilus.org>
 
        * acinclude.m4: Look for a 64-bit integer type.
index 0e69a45e77bf5b854be549364d8e5a98928e862b..94d14b8b614e9fab0ee3a492237df398eb7198d6 100644 (file)
@@ -59,7 +59,7 @@ struct crypt_mechs_s {
 
 /* exported functions */
 extern void ircd_crypt_init(void);
-extern const char* ircd_crypt(const char* key, const char* salt);
+extern char* ircd_crypt(const char* key, const char* salt);
 extern int ircd_crypt_register_mech(crypt_mech_t* mechanism);
 extern int ircd_crypt_unregister_mech(crypt_mech_t* mechanism);
 
index ffee6717f033e11b9dee79c4a6b7298d3f485fde..257e70d998d38df60b9a4c6b32f356ec37cf64ae 100644 (file)
@@ -314,6 +314,7 @@ engine_loop(struct Generators *gen)
     }
     timer_run();
   }
+  MyFree(events);
 }
 
 /** Descriptor for dpoll event engine. */
index 98ee5882cd09d69b975b3824437941e74ef3f40c..c96c564538da52cee6bf2f22a9bf469bdb44b072 100644 (file)
@@ -121,13 +121,13 @@ return 0;
 /** Wrapper for generating a hashed password passed on the supplied password
  * @param key Pointer to the password we want crypted
  * @param salt Pointer to the password we're comparing to (for the salt)
- * @return Pointer to the generated password.
- *  
+ * @return Pointer to the generated password (must be MyFree()'d).
+ *
  * This is a wrapper function which attempts to establish the password
- * format and funnel it off to the correct mechanism handler function.  The 
+ * format and funnel it off to the correct mechanism handler function.  The
  * returned password is compared in the oper_password_match() routine.
 */
-const char* ircd_crypt(const char* key, const char* salt)
+char* ircd_crypt(const char* key, const char* salt)
 {
 char *hashed_pass = NULL;
 const char *temp_hashed_pass, *mysalt;
index 68b78d87cdd8214cebe1be4577bd270e4d8cf34b..af583ff89c55fc5018be370d508309a75358afb3 100644 (file)
@@ -83,7 +83,8 @@ static void to64(char *s, unsigned long v, int n)
 const char* ircd_crypt_smd5(const char* key, const char* salt)
 {
 const char *magic = "$1$";
-char *passwd, *p;
+static char passwd[120];
+char *p;
 const char *sp, *ep;
 unsigned char final[16];
 int sl, pl, i, j;
@@ -99,11 +100,6 @@ unsigned long l;
  /* Refine the Salt first */
  ep = sp = salt;
 
- if(NULL == (passwd = (char *)MyMalloc(120)))
-  return NULL;
-
- memset(passwd, 0, 120);
-
  for (ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
   continue;
 
@@ -140,9 +136,8 @@ unsigned long l;
   else
    MD5Update(&ctx, (unsigned const char *)key+j, 1);
 
- /* Now make the output string
- strcpy(passwd, magic);
- strncat(passwd, sp, sl); */
+ /* Now make the output string. */
+ memset(passwd, 0, 120);
  strncpy(passwd, sp, sl);
  strcat(passwd, "$");
 
index 47ee82570354aa19ed89399028fe3a8a6c082d63..d0e85a12e3f0bc1dc5a7e2d8548ba999ace556b7 100644 (file)
@@ -84,6 +84,7 @@
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_alloc.h"
 #include "ircd_features.h"
 #include "ircd_log.h"
 #include "ircd_reply.h"
 
 int oper_password_match(const char* to_match, const char* passwd)
 {
+  char *crypted;
+  int res;
   /*
    * use first two chars of the password they send in as salt
    *
@@ -116,12 +119,13 @@ int oper_password_match(const char* to_match, const char* passwd)
   /* we no longer do a CRYPT_OPER_PASSWORD check because a clear 
      text passwords just handled by a fallback mechanism called 
      crypt_clear if it's enabled -- hikari */
-  to_match = ircd_crypt(to_match, passwd);
+  crypted = ircd_crypt(to_match, passwd);
 
   if (to_match == NULL)
    return 0;
-  else
-   return (0 == strcmp(to_match, passwd));
+  res = strcmp(crypted, passwd);
+  MyFree(crypted);
+  return 0 == res;
 }
 
 /*