aboutsummaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2010-12-16 22:15:04 -0800
committerWayne Davison <wayned@samba.org>2010-12-16 22:15:04 -0800
commit14ebc5b618ec6d4668e120acc7a75ae8efd677e7 (patch)
treee8aa2fa661c34e9ac38209575d7359f9bda39386 /options.c
parentaef2b8ce4124db39f715d38c7ade329005645e0d (diff)
downloadandroid_external_rsync-14ebc5b618ec6d4668e120acc7a75ae8efd677e7.tar.gz
android_external_rsync-14ebc5b618ec6d4668e120acc7a75ae8efd677e7.tar.bz2
android_external_rsync-14ebc5b618ec6d4668e120acc7a75ae8efd677e7.zip
Fix crash when --backup-dir is excessively long.
Diffstat (limited to 'options.c')
-rw-r--r--options.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/options.c b/options.c
index 2529fe26..dc135923 100644
--- a/options.c
+++ b/options.c
@@ -2044,17 +2044,18 @@ int parse_arguments(int *argc_p, const char ***argv_p)
return 0;
}
if (backup_dir) {
+ size_t len;
while (*backup_dir == '.' && backup_dir[1] == '/')
backup_dir += 2;
if (*backup_dir == '.' && backup_dir[1] == '\0')
backup_dir++;
- backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
- backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
- if (backup_dir_remainder < 128) {
+ len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
+ if (len > sizeof backup_dir_buf - 128) {
snprintf(err_buf, sizeof err_buf,
"the --backup-dir path is WAY too long.\n");
return 0;
}
+ backup_dir_len = (int)len;
if (!backup_dir_len) {
backup_dir_len = -1;
backup_dir = NULL;
@@ -2062,6 +2063,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
backup_dir_buf[backup_dir_len++] = '/';
backup_dir_buf[backup_dir_len] = '\0';
}
+ backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
}
if (backup_dir) {
/* No need for a suffix or a protect rule. */