Changed strcpy() calls into strlcpy() calls, just to be extra safe.
[rsync/rsync.git] / options.c
index ec57901..47fdaa3 100644 (file)
--- a/options.c
+++ b/options.c
@@ -303,7 +303,7 @@ void usage(enum logcode F)
   rprintf(F," -H, --hard-links            preserve hard links\n");
   rprintf(F," -p, --perms                 preserve permissions\n");
   rprintf(F," -E, --executability         preserve the file's executability\n");
-  rprintf(F,"     --chmod=CHMOD           change destination permissions\n");
+  rprintf(F,"     --chmod=CHMOD           affect file and/or directory permissions\n");
   rprintf(F," -o, --owner                 preserve owner (super-user only)\n");
   rprintf(F," -g, --group                 preserve group\n");
   rprintf(F,"     --devices               preserve device files (super-user only)\n");
@@ -613,8 +613,9 @@ static char err_buf[200];
 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);
@@ -832,7 +833,9 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
 
                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);
@@ -902,10 +905,8 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                case OPT_EXCLUDE_FROM:
                case OPT_INCLUDE_FROM:
                        arg = poptGetOptArg(pc);
-                       if (sanitize_paths) {
+                       if (sanitize_paths)
                                arg = sanitize_path(NULL, arg, NULL, 0, NULL);
-                               die_on_unsafe_path((char*)arg, 0);
-                       }
                        if (server_filter_list.head) {
                                char *cp = strdup(arg);
                                if (!cp)
@@ -1223,14 +1224,10 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                int i;
                for (i = *argc; i-- > 0; )
                        (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0, NULL);
-               if (tmpdir) {
+               if (tmpdir)
                        tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
-                       die_on_unsafe_path(tmpdir, 0);
-               }
-               if (backup_dir) {
+               if (backup_dir)
                        backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
-                       die_on_unsafe_path(backup_dir, 0);
-               }
        }
        if (server_filter_list.head && !am_sender) {
                struct filter_list_struct *elp = &server_filter_list;
@@ -1505,7 +1502,7 @@ void server_options(char **args,int *argc)
                argstr[x++] = 'n';
        if (preserve_links)
                argstr[x++] = 'l';
-       if (xfer_dirs > (recurse || !delete_mode || !am_sender))
+       if (xfer_dirs > (recurse || !delete_mode || !am_sender ? 1 : 0))
                argstr[x++] = 'd';
        if (am_sender) {
                if (keep_dirlinks)
@@ -1780,10 +1777,10 @@ char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
 {
        char *p;
        int not_host;
+       int hostlen;
 
        if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
                char *path;
-               int hostlen;
                s += strlen(URL_PREFIX);
                if ((p = strchr(s, '/')) != NULL) {
                        hostlen = p - s;
@@ -1811,6 +1808,8 @@ char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
        }
 
        if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
+               s++;
+               hostlen = p - s;
                *p = '\0';
                not_host = strchr(s, '/') || !strchr(s, ':');
                *p = ']';
@@ -1820,6 +1819,7 @@ char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
        } else {
                if (!(p = strchr(s, ':')))
                        return NULL;
+               hostlen = p - s;
                *p = '\0';
                not_host = strchr(s, '/') != NULL;
                *p = ':';
@@ -1827,8 +1827,8 @@ char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
                        return NULL;
        }
 
-       *host_ptr = new_array(char, p - s + 1);
-       strlcpy(*host_ptr, s, p - s + 1);
+       *host_ptr = new_array(char, hostlen + 1);
+       strlcpy(*host_ptr, s, hostlen + 1);
 
        if (p[1] == ':') {
                if (port_ptr && !*port_ptr)