]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: remove last uses of sockunion_su2str()
authorJorge Boncompte [DTI2] <jorge@dti2.net>
Tue, 10 Apr 2012 14:57:23 +0000 (16:57 +0200)
committerDavid Lamparter <equinox@diac24.net>
Wed, 2 May 2012 15:03:27 +0000 (17:03 +0200)
Use of this function is prone to memory leaks.

This fixes a memory accounting bug for vty denied connections.

Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@diac24.net>
lib/sockunion.c
lib/sockunion.h
lib/vty.c
lib/vty.h

index 59770529313d523a68951a881ab51437204fd1b4..cfb6f9c5a6921042620c34ff7c11d1e3edfaca52 100644 (file)
@@ -207,25 +207,6 @@ sockunion_str2su (const char *str)
   return NULL;
 }
 
-char *
-sockunion_su2str (union sockunion *su)
-{
-  char str[SU_ADDRSTRLEN];
-
-  switch (su->sa.sa_family)
-    {
-    case AF_INET:
-      inet_ntop (AF_INET, &su->sin.sin_addr, str, sizeof (str));
-      break;
-#ifdef HAVE_IPV6
-    case AF_INET6:
-      inet_ntop (AF_INET6, &su->sin6.sin6_addr, str, sizeof (str));
-      break;
-#endif /* HAVE_IPV6 */
-    }
-  return XSTRDUP (MTYPE_TMP, str);
-}
-
 /* Convert IPv4 compatible IPv6 address to IPv4 address. */
 static void
 sockunion_normalise_mapped (union sockunion *su)
index 15b97fc54faf9dd5fa820ed287ca40a03d1ed795..8b06058688229009ddc89ee89f700232dab8a42e 100644 (file)
@@ -94,7 +94,6 @@ extern const char *sockunion2str (union sockunion *, char *, size_t);
 extern int sockunion_cmp (union sockunion *, union sockunion *);
 extern int sockunion_same (union sockunion *, union sockunion *);
 
-extern char *sockunion_su2str (union sockunion *su);
 extern union sockunion *sockunion_str2su (const char *str);
 extern struct in_addr sockunion_get_in_addr (union sockunion *su);
 extern int sockunion_accept (int sock, union sockunion *);
index 9a4efe6416bd3c8f66f707de12e2e732b8f38280..70bf5645bbb2c54a8977fd55afcd408a26f15ed5 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1612,13 +1612,16 @@ vty_flush (struct thread *thread)
 static struct vty *
 vty_create (int vty_sock, union sockunion *su)
 {
+  char buf[SU_ADDRSTRLEN];
   struct vty *vty;
 
+  sockunion2str(su, buf, SU_ADDRSTRLEN);
+
   /* Allocate new vty structure and set up default values. */
   vty = vty_new ();
   vty->fd = vty_sock;
   vty->type = VTY_TERM;
-  vty->address = sockunion_su2str (su);
+  strcpy (vty->address, buf);
   if (no_password_check)
     {
       if (restricted_mode)
@@ -1693,7 +1696,7 @@ vty_accept (struct thread *thread)
   int accept_sock;
   struct prefix *p = NULL;
   struct access_list *acl = NULL;
-  char *bufp;
+  char buf[SU_ADDRSTRLEN];
 
   accept_sock = THREAD_FD (thread);
 
@@ -1719,10 +1722,8 @@ vty_accept (struct thread *thread)
       if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) &&
          (access_list_apply (acl, p) == FILTER_DENY))
        {
-         char *buf;
          zlog (NULL, LOG_INFO, "Vty connection refused from %s",
-               (buf = sockunion_su2str (&su)));
-         free (buf);
+               sockunion2str (&su, buf, SU_ADDRSTRLEN));
          close (vty_sock);
          
          /* continue accepting connections */
@@ -1741,10 +1742,8 @@ vty_accept (struct thread *thread)
       if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) &&
          (access_list_apply (acl, p) == FILTER_DENY))
        {
-         char *buf;
          zlog (NULL, LOG_INFO, "Vty connection refused from %s",
-               (buf = sockunion_su2str (&su)));
-         free (buf);
+               sockunion2str (&su, buf, SU_ADDRSTRLEN));
          close (vty_sock);
          
          /* continue accepting connections */
@@ -1767,9 +1766,7 @@ vty_accept (struct thread *thread)
          safe_strerror (errno));
 
   zlog (NULL, LOG_INFO, "Vty connection from %s",
-    (bufp = sockunion_su2str (&su)));
-  if (bufp)
-    XFREE (MTYPE_TMP, bufp);
+       sockunion2str (&su, buf, SU_ADDRSTRLEN));
 
   vty_create (vty_sock, &su);
 
@@ -2193,8 +2190,6 @@ vty_close (struct vty *vty)
   if (vty->fd > 0)
     close (vty->fd);
 
-  if (vty->address)
-    XFREE (MTYPE_TMP, vty->address);
   if (vty->buf)
     XFREE (MTYPE_VTY, vty->buf);
 
index 639d74175eb02e67b305ed37df7bee7062c9d726..e5158687d0fa99f68056aefaaf0148b90e466bb3 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -23,6 +23,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
 #include "thread.h"
 #include "log.h"
+#include "sockunion.h"
 
 #define VTY_BUFSIZ 512
 #define VTY_MAXHIST 20
@@ -39,9 +40,6 @@ struct vty
   /* Node status of this vty */
   int node;
 
-  /* What address is this vty comming from. */
-  char *address;
-
   /* Failure count */
   int fail;
 
@@ -118,6 +116,9 @@ struct vty
   /* Timeout seconds and thread. */
   unsigned long v_timeout;
   struct thread *t_timeout;
+
+  /* What address is this vty comming from. */
+  char address[SU_ADDRSTRLEN];
 };
 
 /* Integrated configuration file. */