diff --git a/acls.c b/acls.c index 3cf12eeb0..018ab2820 100644 --- a/acls.c +++ b/acls.c @@ -595,7 +595,7 @@ static void send_ida_entries(int f, const ida_entries *idal) name = numeric_ids ? NULL : add_gid(ida->id); write_varint(f, ida->id); if (inc_recurse && name) { - int len = strlen(name); + size_t len = strlen(name); write_varint(f, xbits | XFLAG_NAME_FOLLOWS); write_byte(f, len); write_buf(f, name, len); @@ -730,7 +730,10 @@ static uchar recv_ida_entries(int f, ida_entries *ent) static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type, mode_t mode) { +#ifndef HAVE_OSX_ACLS uchar computed_mask_bits = 0; +#endif + acl_duo *duo_item; uchar flags; int ndx = read_varint(f); @@ -758,14 +761,15 @@ static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type, mode duo_item->racl.mask_obj = recv_acl_access(f, NULL); if (flags & XMIT_OTHER_OBJ) duo_item->racl.other_obj = recv_acl_access(f, NULL); - if (flags & XMIT_NAME_LIST) - computed_mask_bits |= recv_ida_entries(f, &duo_item->racl.names); #ifdef HAVE_OSX_ACLS /* If we received a superfluous mask, throw it away. */ duo_item->racl.mask_obj = NO_ENTRY; (void)mode; #else + if (flags & XMIT_NAME_LIST) + computed_mask_bits |= recv_ida_entries(f, &duo_item->racl.names); + if (duo_item->racl.names.count && duo_item->racl.mask_obj == NO_ENTRY) { /* Mask must be non-empty with lists. */ if (type == SMB_ACL_TYPE_ACCESS) diff --git a/authenticate.c b/authenticate.c index b7f6ead93..c3f2d2df5 100644 --- a/authenticate.c +++ b/authenticate.c @@ -106,7 +106,7 @@ static const char *check_secret(int module, const char *user, const char *group, STRUCT_STAT st; int ok = 1; int user_len = strlen(user); - int group_len = group ? strlen(group) : 0; + size_t group_len = group ? strlen(group) : 0; char *err; FILE *fh; @@ -140,7 +140,7 @@ static const char *check_secret(int module, const char *user, const char *group, err = "secret not found"; while ((user || group) && fgets(line, sizeof line, fh) != NULL) { const char **ptr, *s = strtok(line, "\n\r"); - int len; + size_t len; if (!s) continue; if (*s == '@') { diff --git a/batch.c b/batch.c index accc4c6e6..e0f760dba 100644 --- a/batch.c +++ b/batch.c @@ -164,7 +164,8 @@ void check_batch_flags(void) static int write_arg(const char *arg) { const char *x, *s; - int len, err = 0; + size_t len; + int err = 0; if (*arg == '-' && (x = strchr(arg, '=')) != NULL) { err |= write(batch_sh_fd, arg, x - arg + 1) != x - arg + 1; @@ -178,13 +179,13 @@ static int write_arg(const char *arg) err |= write(batch_sh_fd, "'", 1) != 1; } len = strlen(s); - err |= write(batch_sh_fd, s, len) != len; + err |= write(batch_sh_fd, s, len) != (ssize_t)len; err |= write(batch_sh_fd, "'", 1) != 1; return err; } len = strlen(arg); - err |= write(batch_sh_fd, arg, len) != len; + err |= write(batch_sh_fd, arg, len) != (ssize_t)len; return err; } @@ -192,9 +193,9 @@ static int write_arg(const char *arg) /* Writes out a space and then an option (or other string) with an optional "=" + arg suffix. */ static int write_opt(const char *opt, const char *arg) { - int len = strlen(opt); + size_t len = strlen(opt); int err = write(batch_sh_fd, " ", 1) != 1; - err = write(batch_sh_fd, opt, len) != len ? 1 : 0; + err = write(batch_sh_fd, opt, len) != (ssize_t)len ? 1 : 0; if (arg) { err |= write(batch_sh_fd, "=", 1) != 1; err |= write_arg(arg); diff --git a/clientserver.c b/clientserver.c index 7c897abc4..04f0f7a92 100644 --- a/clientserver.c +++ b/clientserver.c @@ -71,7 +71,7 @@ char *daemon_auth_choices; int read_only = 0; int module_id = -1; int pid_file_fd = -1; -int early_input_len = 0; +size_t early_input_len = 0; char *early_input = NULL; pid_t namecvt_pid = 0; struct chmod_mode_struct *daemon_chmod_modes; @@ -83,7 +83,7 @@ struct chmod_mode_struct *daemon_chmod_modes; * mode and module_dir is not "/"; otherwise 0. (Note that a chroot- * enabled module can have a non-"/" module_dir these days.) */ char *module_dir = NULL; -unsigned int module_dirlen = 0; +size_t module_dirlen = 0; char *full_module_path; @@ -158,7 +158,7 @@ static int exchange_protocols(int f_in, int f_out, char *buf, size_t bufsiz, int if (motd && *motd) { FILE *f = fopen(motd, "r"); while (f && !feof(f)) { - int len = fread(buf, 1, bufsiz - 1, f); + size_t len = fread(buf, 1, bufsiz - 1, f); if (len > 0) write_buf(f_out, buf, len); } @@ -271,14 +271,14 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char return -1; } early_input_len = st.st_size; - if (early_input_len > (int)sizeof line) { - rprintf(FERROR, "%s is > %d bytes.\n", early_input_file, (int)sizeof line); + if (early_input_len > sizeof line) { + rprintf(FERROR, "%s is > %zu bytes.\n", early_input_file, sizeof line); return -1; } if (early_input_len > 0) { - io_printf(f_out, EARLY_INPUT_CMD "%d\n", early_input_len); + io_printf(f_out, EARLY_INPUT_CMD "%zu\n", early_input_len); while (early_input_len > 0) { - int len; + size_t len; if (feof(f)) { rprintf(FERROR, "Early EOF in %s\n", early_input_file); return -1; @@ -1158,7 +1158,7 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char if (!ret || err_msg) { if (err_msg) { while ((p = strchr(err_msg, '\n')) != NULL) { - int len = p - err_msg + 1; + size_t len = p - err_msg + 1; rwrite(FERROR, err_msg, len, 0); err_msg += len; } @@ -1355,8 +1355,8 @@ int start_daemon(int f_in, int f_out) return -1; if (strncmp(line, EARLY_INPUT_CMD, EARLY_INPUT_CMDLEN) == 0) { - early_input_len = strtol(line + EARLY_INPUT_CMDLEN, NULL, 10); - if (early_input_len <= 0 || early_input_len > BIGPATHBUFLEN) { + early_input_len = strtoul(line + EARLY_INPUT_CMDLEN, NULL, 10); + if (early_input_len == 0 || early_input_len > BIGPATHBUFLEN) { io_printf(f_out, "@ERROR: invalid early_input length\n"); return -1; } @@ -1442,7 +1442,7 @@ static void create_pid_file(void) pidbuf[len++] = '\n'; /* We don't need the buffer to end in a '\0' (and we may not have room to add it). */ #endif - if (write(pid_file_fd, pidbuf, len) != len) + if (len < 0 || write(pid_file_fd, pidbuf, len) != len) fail = "write"; cleanup_set_pid(pid); /* Mark the file for removal on exit, even if the write failed. */ } diff --git a/compat.c b/compat.c index 4ce8c6d01..98deb2eff 100644 --- a/compat.c +++ b/compat.c @@ -458,10 +458,10 @@ void validate_choice_vs_env(int ntype, int num1, int num2) * are removed otherwise the char is prefixed to the duplicate term and, if it * is an opening paren/bracket/brace, the matching closing char is suffixed. * "none" is removed on the client side unless dup_markup != '\0'. */ -int get_default_nno_list(struct name_num_obj *nno, char *to_buf, int to_buf_len, char dup_markup) +size_t get_default_nno_list(struct name_num_obj *nno, char *to_buf, size_t to_buf_len, char dup_markup) { struct name_num_item *nni; - int len = 0, cnt = 0; + size_t len = 0, cnt = 0; char delim = '\0', post_delim; switch (dup_markup) { diff --git a/delete.c b/delete.c index 807661643..fe7aaaaef 100644 --- a/delete.c +++ b/delete.c @@ -51,7 +51,8 @@ static enum delret delete_dir_contents(char *fname, uint16 flags) enum delret ret; unsigned remainder; void *save_filters; - int j, dlen; + int j; + size_t dlen; char *p; if (DEBUG_GTE(DEL, 3)) { diff --git a/exclude.c b/exclude.c index ffe55b167..227000eed 100644 --- a/exclude.c +++ b/exclude.c @@ -43,8 +43,8 @@ extern int trust_sender_args; extern int module_id; extern char curr_dir[MAXPATHLEN]; -extern unsigned int curr_dir_len; -extern unsigned int module_dirlen; +extern size_t curr_dir_len; +extern size_t module_dirlen; filter_rule_list filter_list = { .debug_type = "" }; filter_rule_list cvs_filter_list = { .debug_type = " [global CVS]" }; @@ -75,8 +75,8 @@ static BOOL parent_dirscan = False; * files. This makes it easier to save the appropriate values when we * "push" down into each subdirectory. */ static filter_rule **mergelist_parents; -static int mergelist_cnt = 0; -static int mergelist_size = 0; +static size_t mergelist_cnt = 0; +static size_t mergelist_size = 0; #define LOCAL_RULE 1 #define REMOTE_RULE 2 @@ -115,13 +115,13 @@ static uchar cur_elide_value = REMOTE_RULE; static void teardown_mergelist(filter_rule *ex) { - int j; + size_t j; if (!ex->u.mergelist) return; if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] deactivating mergelist #%d%s\n", + rprintf(FINFO, "[%s] deactivating mergelist #%zu%s\n", who_am_i(), mergelist_cnt - 1, ex->u.mergelist->debug_type); } @@ -252,7 +252,7 @@ static void add_rule(filter_rule_list *listp, const char *pat, unsigned int pat_ if (rule->rflags & FILTRULE_PERDIR_MERGE) { filter_rule_list *lp; unsigned int len; - int i; + size_t i; if ((cp = strrchr(rule->pattern, '/')) != NULL) cp++; @@ -288,7 +288,7 @@ static void add_rule(filter_rule_list *listp, const char *pat, unsigned int pat_ mergelist_parents = realloc_array(mergelist_parents, filter_rule *, mergelist_size); } if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] activating mergelist #%d%s\n", + rprintf(FINFO, "[%s] activating mergelist #%zu%s\n", who_am_i(), mergelist_cnt, lp->debug_type); } mergelist_parents[mergelist_cnt++] = rule; @@ -378,7 +378,8 @@ void free_implied_include_partial_string() * that the receiver uses to validate the file list from the sender. */ void add_implied_include(const char *arg, int skip_daemon_module) { - int arg_len, saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0; + size_t arg_len; + int saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0; int slash_cnt = 0; const char *cp; char *p; @@ -596,12 +597,12 @@ static void pop_filter_list(filter_rule_list *listp) * value and will be updated with the length of the resulting name. We * always return a name that is null terminated, even if the merge_file * name was not. */ -static char *parse_merge_name(const char *merge_file, unsigned int *len_ptr, - unsigned int prefix_skip) +static char *parse_merge_name(const char *merge_file, size_t *len_ptr, + size_t prefix_skip) { static char buf[MAXPATHLEN]; char *fn, tmpbuf[MAXPATHLEN]; - unsigned int fn_len; + size_t fn_len; if (!parent_dirscan && *merge_file != '/') { /* Return the name unchanged it doesn't have any slashes. */ @@ -654,9 +655,9 @@ static char *parse_merge_name(const char *merge_file, unsigned int *len_ptr, } /* Sets the dirbuf and dirbuf_len values. */ -void set_filter_dir(const char *dir, unsigned int dirlen) +void set_filter_dir(const char *dir, size_t dirlen) { - unsigned int len; + size_t len; if (*dir != '/') { memcpy(dirbuf, curr_dir, curr_dir_len); dirbuf[curr_dir_len] = '/'; @@ -683,18 +684,18 @@ void set_filter_dir(const char *dir, unsigned int dirlen) * parent directory of the first transfer dir. If it does, we scan all the * dirs from that point through the parent dir of the transfer dir looking * for the per-dir merge-file in each one. */ -static BOOL setup_merge_file(int mergelist_num, filter_rule *ex, +static BOOL setup_merge_file(size_t mergelist_num, filter_rule *ex, filter_rule_list *lp) { char buf[MAXPATHLEN]; char *x, *y, *pat = ex->pattern; - unsigned int len; + size_t len; if (!(x = parse_merge_name(pat, NULL, 0)) || *x != '/') return 0; if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] performing parent_dirscan for mergelist #%d%s\n", + rprintf(FINFO, "[%s] performing parent_dirscan for mergelist #%zi%s\n", who_am_i(), mergelist_num, lp->debug_type); } y = strrchr(x, '/'); @@ -739,7 +740,7 @@ static BOOL setup_merge_file(int mergelist_num, filter_rule *ex, } parent_dirscan = False; if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] completed parent_dirscan for mergelist #%d%s\n", + rprintf(FINFO, "[%s] completed parent_dirscan for mergelist #%zu%s\n", who_am_i(), mergelist_num, lp->debug_type); } free(pat); @@ -755,10 +756,10 @@ struct local_filter_state { * handle all the per-dir merge-files. The "dir" value is the current path * relative to curr_dir (which might not be null-terminated). We copy it * into dirbuf so that we can easily append a file name on the end. */ -void *push_local_filters(const char *dir, unsigned int dirlen) +void *push_local_filters(const char *dir, size_t dirlen) { struct local_filter_state *push; - int i; + size_t i; set_filter_dir(dir, dirlen); if (DEBUG_GTE(FILTER, 2)) { @@ -793,7 +794,7 @@ void *push_local_filters(const char *dir, unsigned int dirlen) lp = ex->u.mergelist; if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] pushing mergelist #%d%s\n", + rprintf(FINFO, "[%s] pushing mergelist #%zu%s\n", who_am_i(), i, lp->debug_type); } @@ -871,7 +872,7 @@ void pop_local_filters(void *mem) free(pop); } -void change_local_filter_dir(const char *dname, int dlen, int dir_depth) +void change_local_filter_dir(const char *dname, size_t dlen, int dir_depth) { static int cur_depth = -1; static void *filt_array[MAXPATHLEN/2+1]; @@ -968,8 +969,8 @@ static int rule_matches(const char *fname, filter_rule *ex, int name_flags) if (strcmp(name, pattern) == 0) return ret_match; } else { - int l1 = strlen(name); - int l2 = strlen(pattern); + size_t l1 = strlen(name); + size_t l2 = strlen(pattern); if (l2 <= l1 && strcmp(name+(l1-l2),pattern) == 0 && (l1==l2 || name[l1-(l2+1)] == '/')) { @@ -1090,11 +1091,11 @@ static const uchar *rule_strcmp(const uchar *str, const char *rule, int rule_len * template rflags and the xflags additionally affect parsing. */ static filter_rule *parse_rule_tok(const char **rulestr_ptr, const filter_rule *template, int xflags, - const char **pat_ptr, unsigned int *pat_len_ptr) + const char **pat_ptr, size_t *pat_len_ptr) { const uchar *s = (const uchar *)*rulestr_ptr; filter_rule *rule; - unsigned int len; + size_t len; if (template->rflags & FILTRULE_WORD_SPLIT) { /* Skip over any initial whitespace. */ @@ -1368,7 +1369,7 @@ void parse_filter_str(filter_rule_list *listp, const char *rulestr, { filter_rule *rule; const char *pat; - unsigned int pat_len; + size_t pat_len; if (!rulestr) return; @@ -1418,7 +1419,7 @@ void parse_filter_str(filter_rule_list *listp, const char *rulestr, if (new_rflags & FILTRULE_PERDIR_MERGE) { if (parent_dirscan) { const char *p; - unsigned int len = pat_len; + size_t len = pat_len; if ((p = parse_merge_name(pat, &len, module_dirlen))) add_rule(listp, p, len, rule, 0); else @@ -1427,7 +1428,7 @@ void parse_filter_str(filter_rule_list *listp, const char *rulestr, } } else { const char *p; - unsigned int len = pat_len; + size_t len = pat_len; if ((p = parse_merge_name(pat, &len, 0))) parse_filter_file(listp, p, rule, XFLG_FATAL_ERRORS); free_filter(rule); diff --git a/flist.c b/flist.c index 464d556ec..7c3369b28 100644 --- a/flist.c +++ b/flist.c @@ -400,7 +400,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, #ifdef SUPPORT_HARD_LINKS int first_hlink_ndx = -1; #endif - int l1, l2; + size_t l1, l2; int xflags; /* Initialize starting value of xflags and adjust counts. */ @@ -600,7 +600,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, else { write_varint(f, uid); if (xflags & XMIT_USER_NAME_FOLLOWS) { - int len = strlen(user_name); + size_t len = strlen(user_name); write_byte(f, len); write_buf(f, user_name, len); } @@ -612,7 +612,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, else { write_varint(f, gid); if (xflags & XMIT_GROUP_NAME_FOLLOWS) { - int len = strlen(group_name); + size_t len = strlen(group_name); write_byte(f, len); write_buf(f, group_name, len); } @@ -1681,7 +1681,7 @@ static void send_if_directory(int f, struct file_list *flist, if (S_ISDIR(file->mode) && !(file->flags & FLAG_MOUNT_DIR) && f_name(file, fbuf)) { void *save_filters; - unsigned int len = strlen(fbuf); + size_t len = strlen(fbuf); if (len > 1 && fbuf[len-1] == '/') fbuf[--len] = '\0'; save_filters = push_local_filters(fbuf, len); @@ -1907,7 +1907,8 @@ static void send_implied_dirs(int f, struct file_list *flist, char *fname, struct file_struct *file; item_list *relname_list; relnamecache **rnpp; - int len, need_new_dir, depth = 0; + size_t len; + int need_new_dir, depth = 0; filter_rule_list save_filter_list = filter_list; flags = (flags | FLAG_IMPLIED_DIR) & ~(FLAG_TOP_DIR | FLAG_CONTENT_DIR); @@ -2011,8 +2012,8 @@ static void send1extra(int f, struct file_struct *file, struct file_list *flist) { char fbuf[MAXPATHLEN]; item_list *relname_list; - int len, dlen, flags = FLAG_DIVERT_DIRS | FLAG_CONTENT_DIR; - size_t j; + int flags = FLAG_DIVERT_DIRS | FLAG_CONTENT_DIR; + size_t len, dlen, j; f_name(file, fbuf); dlen = strlen(fbuf); @@ -2049,7 +2050,7 @@ static void send1extra(int f, struct file_struct *file, struct file_list *flist) fbuf[dlen] = '/'; len = strlcpy(fbuf + dlen + 1, rnp->fname, sizeof fbuf - dlen - 1); free(rnp); - if (len >= (int)sizeof fbuf) + if (len >= sizeof fbuf) continue; /* Impossible... */ slash = strchr(fbuf+dlen+1, '/'); @@ -3353,7 +3354,7 @@ char *f_name(const struct file_struct *f, char *fbuf) fbuf = f_name_buf(); if (f->dirname) { - int len = strlen(f->dirname); + size_t len = strlen(f->dirname); memcpy(fbuf, f->dirname, len); fbuf[len] = '/'; strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1)); diff --git a/generator.c b/generator.c index 110db28fc..b6a3fa992 100644 --- a/generator.c +++ b/generator.c @@ -317,7 +317,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t fs_dev) /* If an item in dirlist is not found in flist, delete it * from the filesystem. */ - for (i = dirlist->used; i--; ) { + for (i = dirlist->used; i-- > 0; ) { struct file_struct *fp = dirlist->files[i]; if (!F_IS_ACTIVE(fp)) continue; diff --git a/ifuncs.h b/ifuncs.h index 956fc22eb..165a454d3 100644 --- a/ifuncs.h +++ b/ifuncs.h @@ -105,7 +105,7 @@ free_stat_x(stat_x *sx_p) static inline char *my_strdup(const char *str, const char *file, int line) { - int len = strlen(str)+1; + size_t len = strlen(str)+1; char *buf = my_alloc(NULL, len, 1, file, line); memcpy(buf, str, len); return buf; diff --git a/io.c b/io.c index a99ac0ec5..d91b8131f 100644 --- a/io.c +++ b/io.c @@ -1292,7 +1292,8 @@ void read_args(int f_in, char *mod_name, char *buf, size_t bufsiz, int rl_nulls, char ***argv_p, int *argc_p, char **request_p) { int maxargs = MAX_ARGS; - int dot_pos = 0, argc = 0, request_len = 0; + int dot_pos = 0, argc = 0; + size_t request_len = 0; char **argv, *p; int rl_flags = (rl_nulls ? RL_EOL_NULLS : 0); @@ -1318,7 +1319,7 @@ void read_args(int f_in, char *mod_name, char *buf, size_t bufsiz, int rl_nulls, if (dot_pos) { if (request_p && request_len < 1024) { - int len = strlen(buf); + size_t len = strlen(buf); if (request_len) request_p[0][request_len++] = ' '; *request_p = realloc_array(*request_p, char, request_len + len + 1); @@ -2089,7 +2090,7 @@ void write_varint(int f, int32 x) { char b[5]; uchar bit; - int cnt; + size_t cnt; SIVAL(b, 1, x); @@ -2111,7 +2112,7 @@ void write_varlong(int f, int64 x, uchar min_bytes) { char b[9]; uchar bit; - int cnt = 8; + size_t cnt = 8; #if SIZEOF_INT64 >= 8 SIVAL64(b, 1, x); @@ -2218,14 +2219,14 @@ void write_byte(int f, uchar c) write_buf(f, (char *)&c, 1); } -void write_vstring(int f, const char *str, int len) +void write_vstring(int f, const char *str, size_t len) { uchar lenbuf[3], *lb = lenbuf; if (len > 0x7F) { if (len > 0x7FFF) { rprintf(FERROR, - "attempting to send over-long vstring (%d > %d)\n", + "attempting to send over-long vstring (%zu > %d)\n", len, 0x7FFF); exit_cleanup(RERR_PROTOCOL); } diff --git a/lib/compat.c b/lib/compat.c index 513d79b23..36c6db335 100644 --- a/lib/compat.c +++ b/lib/compat.c @@ -170,9 +170,10 @@ int sys_gettimeofday(struct timeval *tv) char *do_big_num(int64 num, int human_flag, const char *fract) { static char bufs[4][128]; /* more than enough room */ - static unsigned int n; + static size_t n; char *s; - int len, negated; + size_t len; + int negated; if (human_flag && !number_separator) (void)get_number_separator(); diff --git a/loadparm.c b/loadparm.c index 3906bc0f4..3bdbe0210 100644 --- a/loadparm.c +++ b/loadparm.c @@ -168,7 +168,7 @@ static char *expand_vars(const char *str) { char *buf, *t; const char *f; - int bufsize; + size_t bufsize; if (!str || !strchr(str, '%')) return (char *)str; /* TODO change return value to const char* at some point. */ @@ -179,19 +179,22 @@ static char *expand_vars(const char *str) for (t = buf, f = str; bufsize && *f; ) { if (*f == '%' && isUpper(f+1)) { char *percent = strchr(f+1, '%'); - if (percent && percent - f < bufsize) { - char *val; - strlcpy(t, f+1, percent - f); - val = getenv(t); - if (val) { - int len = strlcpy(t, val, bufsize+1); - if (len > bufsize) - break; - bufsize -= len; - t += len; - f = percent + 1; - continue; - } + if (percent) { + size_t diff = percent - f; + if (diff < bufsize) { + char *val; + strlcpy(t, f+1, diff); + val = getenv(t); + if (val) { + size_t len = strlcpy(t, val, bufsize+1); + if (len > bufsize) + break; + bufsize -= len; + t += len; + f = percent + 1; + continue; + } + } } } *t++ = *f++; @@ -443,7 +446,7 @@ static BOOL do_parameter(char *parmname, char *parmvalue) case P_PATH: string_set(parm_ptr, parmvalue); if ((cp = *(char**)parm_ptr) != NULL) { - int len = strlen(cp); + size_t len = strlen(cp); while (len > 1 && cp[len-1] == '/') len--; cp[len] = '\0'; } diff --git a/log.c b/log.c index e4ba1cce2..4d5c2f029 100644 --- a/log.c +++ b/log.c @@ -56,7 +56,7 @@ extern iconv_t ic_recv; #endif extern char curr_dir[MAXPATHLEN]; extern char *full_module_path; -extern unsigned int module_dirlen; +extern size_t module_dirlen; extern char sender_file_sum[MAX_DIGEST_LEN]; extern const char undetermined_hostname[]; @@ -248,7 +248,7 @@ static void filtered_fwrite(FILE *f, const char *in_buf, int in_len, int use_isp /* this is the underlying (unformatted) rsync debugging function. Call * it with FINFO, FERROR_*, FWARNING, FLOG, or FCLIENT. Note: recursion * can happen with certain fatal conditions. */ -void rwrite(enum logcode code, const char *buf, int len, int is_utf8) +void rwrite(enum logcode code, const char *buf, size_t len, int is_utf8) { char trailing_CR_or_NL; FILE *f = msgs2stderr == 1 ? stderr : stdout; @@ -259,10 +259,6 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) iconv_t ic = ic_chck; #endif #endif - - if (len < 0) - exit_cleanup(RERR_MESSAGEIO); - if (msgs2stderr == 1) { /* A normal daemon can get msgs2stderr set if the socket is busted, so we * change the message destination into an FLOG message in order to try to @@ -297,7 +293,7 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) in_block = 1; if (!log_initialised) log_init(0); - strlcpy(msg, buf, MIN((int)sizeof msg, len + 1)); + strlcpy(msg, buf, MIN(sizeof msg, len + 1)); logit(priority, msg); in_block = 0; @@ -729,11 +725,11 @@ static void log_formatted(enum logcode code, const char *format, const char *op, if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { char ch = iflags & ITEM_IS_NEW ? '+' : '?'; - int i; + size_t i; for (i = 2; c[i]; i++) c[i] = ch; } else if (c[0] == '.' || c[0] == 'h' || c[0] == 'c') { - int i; + size_t i; for (i = 2; c[i]; i++) { if (c[i] != '.') break; @@ -759,7 +755,7 @@ static void log_formatted(enum logcode code, const char *format, const char *op, /* Subtract the length of the escape from the string's size. */ total -= p - s + 1; - if (len + total >= (size_t)sizeof buf) { + if (len + total >= sizeof buf) { rprintf(FERROR, "buffer overflow expanding %%%c -- exiting\n", p[0]); @@ -839,7 +835,7 @@ void maybe_log_item(struct file_struct *file, int iflags, int itemizing, const c void log_delete(const char *fname, int mode) { static struct file_struct *file = NULL; - int len = strlen(fname); + size_t len = strlen(fname); const char *fmt; if (!file) { diff --git a/main.c b/main.c index 0c60b86d1..8e81a2030 100644 --- a/main.c +++ b/main.c @@ -66,7 +66,7 @@ extern int protect_args; extern int relative_paths; extern int sanitize_paths; extern int curr_dir_depth; -extern int curr_dir_len; +extern size_t curr_dir_len; extern int module_id; extern int rsync_port; extern int whole_file; @@ -81,7 +81,7 @@ extern int send_msgs_to_gen; extern dev_t filesystem_dev; extern pid_t cleanup_child_pid; extern size_t bwlimit_writemax; -extern unsigned int module_dirlen; +extern size_t module_dirlen; extern BOOL flist_receiving_enabled; extern BOOL want_progress_now; extern BOOL shutting_down; @@ -846,11 +846,11 @@ static void check_alt_basis_dirs(void) for (j = 0; j < basis_dir_cnt; j++) { char *bdir = basis_dir[j]; - int bd_len = strlen(bdir); + size_t bd_len = strlen(bdir); if (bd_len > 1 && bdir[bd_len-1] == '/') bdir[--bd_len] = '\0'; if (dry_run > 1 && *bdir != '/') { - int len = curr_dir_len + 1 + bd_len + 1; + size_t len = curr_dir_len + 1 + bd_len + 1; char *new = new_array(char, len); if (slash && strncmp(bdir, "../", 3) == 0) { /* We want to remove only one leading "../" prefix for diff --git a/options.c b/options.c index fd674754c..ba7ea48fe 100644 --- a/options.c +++ b/options.c @@ -427,7 +427,9 @@ static char *make_output_option(struct output_struct *words, short *levels, ucha static void parse_output_words(struct output_struct *words, short *levels, const char *str, uchar priority) { const char *s; - int j, len, lev; + size_t j; + size_t len; + int lev; for ( ; str; str = s) { if ((s = strchr(str, ',')) != NULL) @@ -447,8 +449,10 @@ static void parse_output_words(struct output_struct *words, short *levels, const output_item_help(words); exit_cleanup(0); } - if (len == 4 && strncasecmp(str, "none", 4) == 0) - len = lev = 0; + if (len == 4 && strncasecmp(str, "none", 4) == 0) { + len = 0; + lev = 0; + } else if (len == 3 && strncasecmp(str, "all", 3) == 0) len = 0; for (j = 0; words[j].name; j++) { @@ -464,7 +468,7 @@ static void parse_output_words(struct output_struct *words, short *levels, const } if (len && !words[j].name && !am_server) { rprintf(FERROR, "Unknown %s item: \"%.*s\"\n", - words[j].help, len, str); + words[j].help, (int)len, str); exit_cleanup(RERR_SYNTAX); } } @@ -1894,7 +1898,7 @@ int parse_arguments(int *argc_p, const char ***argv_p) #endif case OPT_STDERR: { - int len; + size_t len; arg = poptGetOptArg(pc); len = strlen(arg); if (len && strncmp("errors", arg, len) == 0) @@ -2526,8 +2530,8 @@ char *safe_arg(const char *opt, const char *arg) char *escapes = is_filename_arg ? SHELL_CHARS : WILD_CHARS SHELL_CHARS; BOOL escape_leading_dash = is_filename_arg && *arg == '-'; BOOL escape_leading_tilde = 0; - int len1 = opt && *opt ? strlen(opt) + 1 : 0; - int len2 = strlen(arg); + size_t len1 = opt && *opt ? strlen(opt) + 1 : 0; + size_t len2 = strlen(arg); int extras = escape_leading_dash ? 2 : 0; char *ret; if (!protect_args && old_style_args < 2 && (!old_style_args || (!is_filename_arg && opt != SPLIT_ARG_WHEN_OLD))) { diff --git a/popt/popthelp.c b/popt/popthelp.c index 6a009766d..f42fdf256 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -757,7 +757,7 @@ static size_t singleTableUsage(poptContext con, FILE * fp, size_t cursor, * @retval str concatenation of short options * @return length of display string */ -static int showShortOptions(const struct poptOption * opt, FILE * fp, +static size_t showShortOptions(const struct poptOption * opt, FILE * fp, /*@null@*/ char * str) /*@globals fileSystem @*/ /*@modifies *str, *fp, fileSystem @*/ @@ -765,7 +765,7 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp, { /* bufsize larger then the ascii set, lazy alloca on top level call. */ char * s = (str != NULL ? str : memset(alloca(300), 0, 300)); - int len = 0; + size_t len = 0; if (s == NULL) return 0; diff --git a/popt/poptparse.c b/popt/poptparse.c index e003a04a9..3130cde83 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -135,12 +135,11 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl char * p; char * q; char * x; - int t; - int argvlen = 0; + size_t t; + size_t argvlen = 0; size_t maxlinelen = sizeof(line); size_t linelen; - int maxargvlen = 480; - int linenum = 0; + size_t maxargvlen = 480; *argstrp = NULL; @@ -155,7 +154,6 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl if (argstr == NULL) return POPT_ERROR_MALLOC; while (fgets(line, (int)maxlinelen, fp) != NULL) { - linenum++; p = line; /* loop until first non-space char or EOL */ diff --git a/socket.c b/socket.c index c2075adf8..6c906f70f 100644 --- a/socket.c +++ b/socket.c @@ -340,8 +340,8 @@ int open_socket_out_wrapped(char *host, int port, const char *bind_addr, int af_ char *prog = getenv("RSYNC_CONNECT_PROG"); if (prog && strchr(prog, '%')) { - int hlen = strlen(host); - int len = strlen(prog) + 1; + size_t hlen = strlen(host); + size_t len = strlen(prog) + 1; char *f, *t; for (f = prog; *f; f++) { if (*f != '%') diff --git a/syscall.c b/syscall.c index d92074aaa..ef097dc7e 100644 --- a/syscall.c +++ b/syscall.c @@ -94,10 +94,12 @@ int do_symlink(const char *lnk, const char *path) /* For --fake-super, we create a normal file with mode 0600 * and write the lnk into it. */ if (am_root < 0) { - int ok, len = strlen(lnk); + int ok; + size_t len; int fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR|S_IRUSR); if (fd < 0) return -1; + len = strlen(lnk); ok = write(fd, lnk, len) == len; if (close(fd) < 0) ok = 0; @@ -115,7 +117,7 @@ ssize_t do_readlink(const char *path, char *buf, size_t bufsiz) if (am_root < 0) { int fd = do_open_nofollow(path, O_RDONLY); if (fd >= 0) { - int len = read(fd, buf, bufsiz); + ssize_t len = read(fd, buf, bufsiz); close(fd); return len; } @@ -299,7 +301,7 @@ int do_ftruncate(int fd, OFF_T size) void trim_trailing_slashes(char *name) { - int l; + size_t l; /* Some BSD systems cannot make a directory if the name * contains a trailing slash. * */ diff --git a/t_stub.c b/t_stub.c index 085378a82..7deb3bbae 100644 --- a/t_stub.c +++ b/t_stub.c @@ -28,7 +28,7 @@ int preallocate_files = 0; int protect_args = 0; int module_id = -1; int relative_paths = 0; -int module_dirlen = 0; +size_t module_dirlen = 0; int preserve_xattrs = 0; int preserve_perms = 0; int preserve_executability = 0; diff --git a/tls.c b/tls.c index e6b0708ad..f91d7abd3 100644 --- a/tls.c +++ b/tls.c @@ -138,7 +138,7 @@ static void storetime(char *dest, size_t destsize, time_t t, int nsecs) snprintf(dest + len, destsize - len, ".%09d", nsecs); } else { int has_nsecs = nsecs >= 0 ? 1 : 0; - int len = MIN(20 + 10*has_nsecs, (int)destsize - 1); + size_t len = MIN(20 + 10*has_nsecs, (int)destsize - 1); memset(dest, ' ', len); dest[len] = '\0'; } diff --git a/uidlist.c b/uidlist.c index 99a34679a..a0b5ff146 100644 --- a/uidlist.c +++ b/uidlist.c @@ -372,7 +372,7 @@ const char *add_gid(gid_t gid) static void send_one_name(int f, id_t id, const char *name) { - int len; + size_t len; if (!name) name = ""; @@ -416,7 +416,7 @@ void send_id_lists(int f) uid_t recv_user_name(int f, uid_t uid) { struct idlist *node; - int len = read_byte(f); + size_t len = read_byte(f); char *name; if (len) { @@ -436,7 +436,7 @@ uid_t recv_user_name(int f, uid_t uid) gid_t recv_group_name(int f, gid_t gid, uint16 *flags_ptr) { struct idlist *node; - int len = read_byte(f); + size_t len = read_byte(f); char *name; if (len) { diff --git a/util1.c b/util1.c index da50ff1e8..7d8086635 100644 --- a/util1.c +++ b/util1.c @@ -35,14 +35,14 @@ extern int preserve_xattrs; extern int omit_link_times; extern int preallocate_files; extern char *module_dir; -extern unsigned int module_dirlen; +extern size_t module_dirlen; extern char *partial_dir; extern filter_rule_list daemon_filter_list; int sanitize_paths = 0; char curr_dir[MAXPATHLEN]; -unsigned int curr_dir_len; +size_t curr_dir_len; int curr_dir_depth; /* This is only set for a sanitizing daemon. */ /* Set a fd into nonblocking mode. */ @@ -638,7 +638,7 @@ static struct glob_data { static void glob_match(char *arg, int abpos, int fbpos) { - int len; + size_t len; char *slash; while (*arg == '.' && arg[1] == '/') { @@ -788,7 +788,7 @@ void glob_expand_module(char *base1, char *arg, char ***argv_p, int *argc_p, int { char *p, *s; char *base = base1; - int base_len = strlen(base); + size_t base_len = strlen(base); if (!arg || !*arg) return; @@ -940,7 +940,7 @@ int count_dir_elements(const char *p) * CFN_KEEP_TRAILING_SLASH is flagged, and will also collapse ".." elements * (except at the start) if CFN_COLLAPSE_DOT_DOT_DIRS is flagged. If the * resulting name would be empty, returns ".". */ -int clean_fname(char *name, int flags) +size_t clean_fname(char *name, int flags) { char *limit = name - 1, *t = name, *f = name; int anchored; @@ -1035,10 +1035,11 @@ int clean_fname(char *name, int flags) char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth, int flags) { char *start, *sanp; - int rlen = 0, drop_dot_dirs = !relative_paths || !(flags & SP_KEEP_DOT_DIRS); + size_t rlen = 0; + int drop_dot_dirs = !relative_paths || !(flags & SP_KEEP_DOT_DIRS); if (dest != p) { - int plen = strlen(p); /* the path len INCLUDING any separating slash */ + size_t plen = strlen(p); /* the path len INCLUDING any separating slash */ if (*p == '/') { if (!rootdir) rootdir = module_dir; @@ -1113,7 +1114,7 @@ char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth, i int change_dir(const char *dir, int set_path_only) { static int initialised, skipped_chdir; - unsigned int len; + size_t len; if (!initialised) { initialised = 1; @@ -1141,7 +1142,7 @@ int change_dir(const char *dir, int set_path_only) skipped_chdir = set_path_only; memcpy(curr_dir, dir, len + 1); } else { - unsigned int save_dir_len = curr_dir_len; + size_t save_dir_len = curr_dir_len; if (curr_dir_len + 1 + len >= sizeof curr_dir) { errno = ENAMETOOLONG; return 0; @@ -1173,12 +1174,12 @@ int change_dir(const char *dir, int set_path_only) /* This will make a relative path absolute and clean it up via clean_fname(). * Returns the string, which might be newly allocated, or NULL on error. */ -char *normalize_path(char *path, BOOL force_newbuf, unsigned int *len_ptr) +char *normalize_path(char *path, BOOL force_newbuf, size_t *len_ptr) { - unsigned int len; + size_t len; if (*path != '/') { /* Make path absolute. */ - int len = strlen(path); + len = strlen(path); if (curr_dir_len + 1 + len >= sizeof curr_dir) return NULL; curr_dir[curr_dir_len] = '/'; @@ -1236,20 +1237,20 @@ static char partial_fname[MAXPATHLEN]; char *partial_dir_fname(const char *fname) { char *t = partial_fname; - int sz = sizeof partial_fname; + size_t sz = sizeof partial_fname; const char *fn; if ((fn = strrchr(fname, '/')) != NULL) { fn++; if (*partial_dir != '/') { - int len = fn - fname; + size_t len = fn - fname; strncpy(t, fname, len); /* safe */ t += len; sz -= len; } } else fn = fname; - if ((int)pathjoin(t, sz, partial_dir, fn) >= sz) + if (pathjoin(t, sz, partial_dir, fn) >= sz) return NULL; if (daemon_filter_list.head) { t = strrchr(partial_fname, '/');