Changed strcpy() calls into strlcpy() calls, just to be extra safe.
authorWayne Davison <wayned@samba.org>
Fri, 13 Oct 2006 23:17:33 +0000 (23:17 +0000)
committerWayne Davison <wayned@samba.org>
Fri, 13 Oct 2006 23:17:33 +0000 (23:17 +0000)
lib/permstring.c
lib/pool_alloc.c
log.c
options.c
progress.c
tls.c

index 304b2a9..ba981ee 100644 (file)
@@ -30,7 +30,7 @@ void permstring(char *perms, mode_t mode)
        static const char *perm_map = "rwxrwxrwx";
        int i;
 
        static const char *perm_map = "rwxrwxrwx";
        int i;
 
-       strcpy(perms, "----------");
+       strlcpy(perms, "----------", 11);
 
        for (i = 0; i < 9; i++) {
                if (mode & (1 << i))
 
        for (i = 0; i < 9; i++) {
                if (mode & (1 << i))
index ac655a5..1ec381d 100644 (file)
@@ -272,7 +272,7 @@ pool_stats(alloc_pool_t p, int fd, int summarize)
 
        if (pool->live)
                FDEXTSTAT(pool->live);
 
        if (pool->live)
                FDEXTSTAT(pool->live);
-       strcpy(buf, "   FREE    BOUND\n");
+       strlcpy(buf, "   FREE    BOUND\n", sizeof buf);
        write(fd, buf, strlen(buf));
 
        for (cur = pool->free; cur; cur = cur->next)
        write(fd, buf, strlen(buf));
 
        for (cur = pool->free; cur; cur = cur->next)
diff --git a/log.c b/log.c
index 9d18770..ef91f98 100644 (file)
--- a/log.c
+++ b/log.c
@@ -394,7 +394,7 @@ void rsyserr(enum logcode code, int errcode, const char *format, ...)
        char buf[BIGPATHBUFLEN];
        size_t len;
 
        char buf[BIGPATHBUFLEN];
        size_t len;
 
-       strcpy(buf, RSYNC_NAME ": ");
+       strlcpy(buf, RSYNC_NAME ": ", sizeof buf);
        len = (sizeof RSYNC_NAME ": ") - 1;
 
        va_start(ap, format);
        len = (sizeof RSYNC_NAME ": ") - 1;
 
        va_start(ap, format);
@@ -544,15 +544,15 @@ static void log_formatted(enum logcode code, char *format, char *op,
                case 'L':
                        if (hlink && *hlink) {
                                n = hlink;
                case 'L':
                        if (hlink && *hlink) {
                                n = hlink;
-                               strcpy(buf2, " => ");
+                               strlcpy(buf2, " => ", sizeof buf2);
                        } else if (S_ISLNK(file->mode) && file->u.link) {
                                n = file->u.link;
                        } else if (S_ISLNK(file->mode) && file->u.link) {
                                n = file->u.link;
-                               strcpy(buf2, " -> ");
+                               strlcpy(buf2, " -> ", sizeof buf2);
                        } else {
                                n = "";
                                if (!fmt[1])
                                        break;
                        } else {
                                n = "";
                                if (!fmt[1])
                                        break;
-                               strcpy(buf2, "    ");
+                               strlcpy(buf2, "    ", sizeof buf2);
                        }
                        strlcat(fmt, "s", sizeof fmt);
                        snprintf(buf2 + 4, sizeof buf2 - 4, fmt, n);
                        }
                        strlcat(fmt, "s", sizeof fmt);
                        snprintf(buf2 + 4, sizeof buf2 - 4, fmt, n);
index 05df91e..47fdaa3 100644 (file)
--- a/options.c
+++ b/options.c
@@ -613,8 +613,9 @@ static char err_buf[200];
 void option_error(void)
 {
        if (!err_buf[0]) {
 void option_error(void)
 {
        if (!err_buf[0]) {
-               strcpy(err_buf, "Error parsing options: "
-                   "option may be supported on client but not on server?\n");
+               strlcpy(err_buf, "Error parsing options: option may "
+                       "be supported on client but not on server?\n",
+                       sizeof err_buf);
        }
 
        rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
        }
 
        rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
@@ -832,7 +833,9 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
 
                case OPT_DAEMON:
                        if (am_daemon) {
 
                case OPT_DAEMON:
                        if (am_daemon) {
-                               strcpy(err_buf, "Attempt to hack rsync thwarted!\n");
+                               strlcpy(err_buf,
+                                       "Attempt to hack rsync thwarted!\n",
+                                       sizeof err_buf);
                                return 0;
                        }
                        poptFreeContext(pc);
                                return 0;
                        }
                        poptFreeContext(pc);
index 3cf2ad7..fcd2a3d 100644 (file)
@@ -104,7 +104,7 @@ static void rprint_progress(OFF_T ofs, OFF_T size, struct timeval *now,
                        stats.num_files - stats.current_file_index - 1,
                        stats.num_files);
        } else
                        stats.num_files - stats.current_file_index - 1,
                        stats.num_files);
        } else
-               strcpy(eol, "\r");
+               strlcpy(eol, "\r", sizeof eol);
        rprintf(FCLIENT, "%12s %3d%% %7.2f%s %4d:%02d:%02d%s",
                human_num(ofs), pct, rate, units,
                remain_h, remain_m, remain_s, eol);
        rprintf(FCLIENT, "%12s %3d%% %7.2f%s %4d:%02d:%02d%s",
                human_num(ofs), pct, rate, units,
                remain_h, remain_m, remain_s, eol);
diff --git a/tls.c b/tls.c
index 425d701..719c8c5 100644 (file)
--- a/tls.c
+++ b/tls.c
@@ -74,7 +74,7 @@ static void list_file(const char *fname)
                buf.st_mode &= ~0777;
                buf.st_mtime = (time_t)0;
                buf.st_uid = buf.st_gid = 0;
                buf.st_mode &= ~0777;
                buf.st_mtime = (time_t)0;
                buf.st_uid = buf.st_gid = 0;
-               strcpy(linkbuf, " -> ");
+               strlcpy(linkbuf, " -> ", sizeof linkbuf);
                /* const-cast required for silly UNICOS headers */
                len = readlink((char *) fname, linkbuf+4, sizeof(linkbuf) - 4);
                if (len == -1)
                /* const-cast required for silly UNICOS headers */
                len = readlink((char *) fname, linkbuf+4, sizeof(linkbuf) - 4);
                if (len == -1)
@@ -99,7 +99,7 @@ static void list_file(const char *fname)
                        (int)mt->tm_min,
                        (int)mt->tm_sec);
        } else {
                        (int)mt->tm_min,
                        (int)mt->tm_sec);
        } else {
-               strcpy(datebuf, "                   ");
+               strlcpy(datebuf, "                   ", sizeof datebuf);
        }
 
        /* TODO: Perhaps escape special characters in fname? */
        }
 
        /* TODO: Perhaps escape special characters in fname? */