]> git.sesse.net Git - betaftpd/commitdiff
list_readmes(): Allocate less memory, use snprintf() to avoid a buffer overflow from...
authorsgunderson <sgunderson>
Thu, 17 Aug 2000 21:12:51 +0000 (21:12 +0000)
committersgunderson <sgunderson>
Thu, 17 Aug 2000 21:12:51 +0000 (21:12 +0000)
ftpd.c

diff --git a/ftpd.c b/ftpd.c
index b36027b51e1da9e6de71b56d33f639842fd8351c..a6e32f8c399a4c15a1adb4d9edd19170dc2889c0 100644 (file)
--- a/ftpd.c
+++ b/ftpd.c
@@ -1584,28 +1584,28 @@ void list_readmes(struct conn * const c)
        const time_t now = time(NULL);
        int i;
 
-       if (glob("README*", 0, NULL, &pglob) == 0) {
-               for (i = 0; i < pglob.gl_pathc; i++) {
-                       const char * const temp = pglob.gl_pathv[i];
-                       struct stat buf;
-                       char str[2048];
+       if (glob("README*", 0, NULL, &pglob) != 0) return;
 
-                       char *tm;
+       for (i = 0; i < pglob.gl_pathc; i++) {
+               const char * const temp = pglob.gl_pathv[i];
+               struct stat buf;
+               char str[256];
 
-                       if (stat(temp, &buf) == -1) continue;
+               char *tm;
 
-                       /* remove trailing LF */
-                       tm = ctime(&buf.st_mtime);
-                       tm[strlen(tm) - 1] = 0;
+               if (stat(temp, &buf) == -1) continue;
 
-                       sprintf(str, "250-Please read the file %s\r\n"
-                                    "250-\tIt was last modified %s - %ld days ago\r\n",
-                               temp, tm,
-                               (now - buf.st_mtime) / 86400);
-                       send(c->sock, str, strlen(str), 0);
-               }
-               globfree(&pglob);
-       }       
+               /* remove trailing LF */
+               tm = ctime(&buf.st_mtime);
+               tm[strlen(tm) - 1] = 0;
+
+               snprintf(str, 256, "250-Please read the file %s\r\n"
+                                  "250-\tIt was last modified %s - %ld days ago\r\n",
+                       temp, tm,
+                       (now - buf.st_mtime) / 86400);
+               send(c->sock, str, strlen(str), 0);
+       }
+       globfree(&pglob);
 }
 #endif