From 786202c1cb4f445a6804cbf2c887b1464c08efbf Mon Sep 17 00:00:00 2001 From: job Date: Tue, 14 Feb 2023 17:15:15 +0000 Subject: [PATCH] Fix handling of port numbers in rsync://host[:port]/module URLs With and OK tb@ --- usr.bin/rsync/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/usr.bin/rsync/main.c b/usr.bin/rsync/main.c index 8aeca786cda..dd175597914 100644 --- a/usr.bin/rsync/main.c +++ b/usr.bin/rsync/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.65 2022/08/02 20:01:12 tb Exp $ */ +/* $OpenBSD: main.c,v 1.66 2023/02/14 17:15:15 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -231,17 +231,21 @@ fargs_parse(size_t argc, char *argv[], struct opts *opts) j = strlen(cp); if (f->remote && strncasecmp(cp, "rsync://", 8) == 0) { - /* rsync://path */ + /* rsync://host[:port]/path */ + size_t module_offset = len; cp += 8; - if ((ccp = strchr(cp, ':'))) /* skip :port */ + /* skip :port */ + if ((ccp = strchr(cp, ':')) != NULL) { *ccp = '\0'; + module_offset += strcspn(ccp + 1, "/") + 1; + } if (strncmp(cp, f->host, len) || (cp[len] != '/' && cp[len] != '\0')) errx(ERR_SYNTAX, "different remote host: %s", f->sources[i]); memmove(f->sources[i], - f->sources[i] + len + 8 + 1, - j - len - 8); + f->sources[i] + module_offset + 8 + 1, + j - module_offset - 8); } else if (f->remote && strncmp(cp, "::", 2) == 0) { /* ::path */ memmove(f->sources[i], -- 2.20.1