diff lib/protocols.c @ 249:094e83b55cb1

2003-8-7 Brian Masney <masneyb@gftp.org> * lib/cache.c lib/misc.c lib/protocols.c lib/pty.c - make sure a NUL byte appears at the end of the buffer after the call to strncpy * lib/rfc959.c - increased buffer size to directory parsing routine
author masneyb
date Fri, 08 Aug 2003 02:24:54 +0000
parents 16a967a4d003
children 71d0098c3735
line wrap: on
line diff
--- a/lib/protocols.c	Fri Aug 08 01:38:12 2003 +0000
+++ b/lib/protocols.c	Fri Aug 08 02:24:54 2003 +0000
@@ -1996,7 +1996,7 @@
     {
       *rbuf = g_malloc0 (sizeof (**rbuf));
       (*rbuf)->max_bufsize = len;
-      (*rbuf)->buffer = g_malloc ((*rbuf)->max_bufsize + 1);
+      (*rbuf)->buffer = g_malloc0 ((*rbuf)->max_bufsize + 1);
 
       if ((ret = read_function (request, (*rbuf)->buffer, 
                                 (*rbuf)->max_bufsize, fd)) <= 0)
@@ -2019,21 +2019,25 @@
       if ((*rbuf)->cur_bufsize > 0 && (pos != NULL || end_of_buffer))
         {
           if (pos != NULL)
-            retval = pos - (*rbuf)->curpos + 1;
-          else
-            retval = (*rbuf)->cur_bufsize;
-
-          if (pos != NULL)
             {
+              retval = pos - (*rbuf)->curpos + 1;
               nextpos = pos + 1;
               if (pos > (*rbuf)->curpos && *(pos - 1) == '\r')
                 pos--;
               *pos = '\0';
             }
           else
-            nextpos = NULL;
+            {
+              retval = (*rbuf)->cur_bufsize;
+              nextpos = NULL;
+
+              /* This is not an overflow since we allocated one extra byte to
+                 buffer above */
+              ((*rbuf)->curpos)[retval] = '\0';
+            }
 
           strncpy (str, (*rbuf)->curpos, len);
+          str[len - 1] = '\0';
           (*rbuf)->cur_bufsize -= retval;
 
           if (nextpos != NULL)