diff options
author | Wayne Davison <wayned@samba.org> | 2006-10-13 07:18:29 +0000 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2006-10-13 07:18:29 +0000 |
commit | d5dcb6f7753020a86973e3a66c632ed0ef9e7832 (patch) | |
tree | 0de00c58d6a8297c579ba404e414d04c8a961c7f /receiver.c | |
parent | 0c25dedf3101373398564ee974875a7760ecb8d2 (diff) | |
download | rsync-d5dcb6f7753020a86973e3a66c632ed0ef9e7832.tar.gz |
Silence some IBM checker warnings and made a slight optimization
to get_tmpname().
Diffstat (limited to 'receiver.c')
-rw-r--r-- | receiver.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -84,15 +84,13 @@ static int updating_basis; static int get_tmpname(char *fnametmp, char *fname) { + int maxname, added, length = 0; char *f; - int length = 0; - int maxname; if (tmpdir) { /* Note: this can't overflow, so the return value is safe */ length = strlcpy(fnametmp, tmpdir, MAXPATHLEN - 2); fnametmp[length++] = '/'; - fnametmp[length] = '\0'; /* always NULL terminated */ } if ((f = strrchr(fname, '/')) != NULL) { @@ -105,8 +103,9 @@ static int get_tmpname(char *fnametmp, char *fname) } else f = fname; fnametmp[length++] = '.'; - fnametmp[length] = '\0'; /* always NULL terminated */ + /* The maxname value is bufsize, and includes space for the '\0'. + * (Note that NAME_MAX get -8 for the leading '.' above.) */ maxname = MIN(MAXPATHLEN - 7 - length, NAME_MAX - 8); if (maxname < 1) { @@ -115,8 +114,10 @@ static int get_tmpname(char *fnametmp, char *fname) return 0; } - strlcpy(fnametmp + length, f, maxname); - strcat(fnametmp + length, ".XXXXXX"); + added = strlcpy(fnametmp + length, f, maxname); + if (added >= maxname) + added = maxname - 1; + memcpy(fnametmp + length + added, ".XXXXXX", 8); return 1; } @@ -519,7 +520,10 @@ int recv_files(int f_in, struct file_list *flist, char *local_name) } } - if (fd1 != -1 && do_fstat(fd1,&st) != 0) { + if (fd1 == -1) { + st.st_mode = 0; + st.st_size = 0; + } else if (do_fstat(fd1,&st) != 0) { rsyserr(FERROR, errno, "fstat %s failed", full_fname(fnamecmp)); discard_receive_data(f_in, file->length); |