summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2007-05-11 17:59:37 +0200
committerYann Dirson <ydirson@altern.org>2008-03-31 16:09:13 +0200
commitb51b03196c338d94a38310786974db7ccd8dadec (patch)
tree13f117dcbc62be8f55005d0b3973f57029b55ef1
parenta543718e6a3d8da81bd0a5b3653dad06f781b663 (diff)
downloadcvsps-b51b03196c338d94a38310786974db7ccd8dadec.tar.gz
Fix parsing of pserver URL in open_ctx_pserver()
-rw-r--r--cvs_direct.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/cvs_direct.c b/cvs_direct.c
index 920487d..a5ad67f 100644
--- a/cvs_direct.c
+++ b/cvs_direct.c
@@ -185,42 +185,42 @@ static CvsServerCtx * open_ctx_pserver(CvsServerCtx * ctx, const char * p_root)
strcpy(root, p_root);
- tok = strsep(&p, ":");
- if (strlen(tok) == 0 || !p)
+ /* parse initial "user@server" portion of p. */
+ tok = strsep(&p, "@");
+ tok2 = p;
+ p += strcspn(p, ":/"); /* server part ends at first ':' or '/'. */
+ if (!tok || !tok2 || !strlen(tok) || 0 >= (p - tok2))
{
- debug(DEBUG_APPERROR, "parse error on third token");
+ debug(DEBUG_APPERROR, "parse error on user@server in pserver");
goto out_free_err;
}
- tok2 = strsep(&tok, "@");
- if (!strlen(tok2) || (!tok || !strlen(tok)))
+ strcpy(user, tok);
+ memcpy(server, tok2, p - tok2);
+ server[p - tok2] = '\0';
+
+ /* p now points to ':' or '/' following server part. */
+ tok = strchr(p, '/'); /* find start of path */
+ if (!tok)
{
- debug(DEBUG_APPERROR, "parse error on user@server in pserver");
+ debug(DEBUG_APPERROR, "parse error: expecting / in root");
goto out_free_err;
}
- strcpy(user, tok2);
- strcpy(server, tok);
-
- if (*p != '/')
+ if (*p == ':') /* port number specified. Ends at tok. */
{
- tok = strchr(p, '/');
- if (!tok)
- {
- debug(DEBUG_APPERROR, "parse error: expecting / in root");
- goto out_free_err;
- }
-
- memset(port, 0, sizeof(port));
+ p++;
memcpy(port, p, tok - p);
-
- p = tok;
+ port[tok - p] = '\0';
}
else
{
strcpy(port, "2401");
}
+ /* Make p point to path component, starting with '/'. */
+ p = tok;
+
/* the line from .cvspass is fully qualified, so rebuild */
snprintf(full_root, PATH_MAX, ":pserver:%s@%s:%s%s", user, server, port, p);
get_cvspass(pass, full_root);