changeset 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 62bc15fc5b34
files ChangeLog lib/cache.c lib/misc.c lib/protocols.c lib/pty.c lib/rfc959.c
diffstat 6 files changed, 27 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Aug 08 01:38:12 2003 +0000
+++ b/ChangeLog	Fri Aug 08 02:24:54 2003 +0000
@@ -1,4 +1,9 @@
 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
+	
 	* lib/protocols.c (gftp_fd_write) - use a signed variable to store the
 	result from write(). Write errors were not being caught properly.
 
@@ -1442,7 +1447,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.129 2003/08/08 01:38:11 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.130 2003/08/08 02:24:53 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/cache.c	Fri Aug 08 01:38:12 2003 +0000
+++ b/lib/cache.c	Fri Aug 08 02:24:54 2003 +0000
@@ -310,6 +310,7 @@
   else if (descr != NULL)
     { 
       strncpy (description, descr, sizeof (description));
+      description[sizeof (description) - 1] = '\0';
     }
   else
     return;
--- a/lib/misc.c	Fri Aug 08 01:38:12 2003 +0000
+++ b/lib/misc.c	Fri Aug 08 02:24:54 2003 +0000
@@ -42,7 +42,10 @@
   if (len == 0)
     {
       if (dest_str != NULL)
-        strncpy (dest_str, "0", dest_len);
+        {
+          strncpy (dest_str, "0", dest_len);
+          dest_str[dest_len - 1] = '\0';
+        }
       else
         dest_str = g_strdup ("0");
       return (dest_str);
--- 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)
--- a/lib/pty.c	Fri Aug 08 01:38:12 2003 +0000
+++ b/lib/pty.c	Fri Aug 08 02:24:54 2003 +0000
@@ -40,6 +40,7 @@
     return (GFTP_ERETRYABLE);
 
   strncpy (pts_name, new_pts_name, len);
+  pts_name[len - 1] = '\0';
 
   return (fdm);
 }
@@ -141,6 +142,7 @@
     }
 
   strncpy (pts_name, new_pts_name, len);
+  pts_name[len - 1] = '\0';
 
   return (fdm);
 }
@@ -187,6 +189,8 @@
   g_return_val_if_fail (len >= 10, GFTP_EFATAL);
 
   strncpy (pts_name, "/dev/ptyXY", len);
+  pts_name[len - 1] = '\0';
+
   for (pos1 = "pqrstuvwxyzPQRST"; *pos1 != '\0'; pos1++) 
     {
       pts_name[8] = *pos1;
--- a/lib/rfc959.c	Fri Aug 08 01:38:12 2003 +0000
+++ b/lib/rfc959.c	Fri Aug 08 02:24:54 2003 +0000
@@ -1385,7 +1385,7 @@
 rfc959_get_next_file (gftp_request * request, gftp_file * fle, int fd)
 {
   rfc959_parms * parms;
-  char tempstr[255];
+  char tempstr[1024];
   ssize_t len;
 
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);