diff options
author | 2013-06-03 17:04:35 +0000 | |
---|---|---|
committer | 2013-06-03 17:04:35 +0000 | |
commit | 52248372437b3c04f32eb3d353415fcbc4b7169d (patch) | |
tree | 4d41904f0088d924d0312299f85bfa5ca9b9ea12 /usr.bin/cvs/rcsparse.c | |
parent | backport commitid support from newer CVS (with a different random id (diff) | |
download | wireguard-openbsd-52248372437b3c04f32eb3d353415fcbc4b7169d.tar.xz wireguard-openbsd-52248372437b3c04f32eb3d353415fcbc4b7169d.zip |
properly handle commitid tokens found in rcs files
ok deraadt
Diffstat (limited to 'usr.bin/cvs/rcsparse.c')
-rw-r--r-- | usr.bin/cvs/rcsparse.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/usr.bin/cvs/rcsparse.c b/usr.bin/cvs/rcsparse.c index 737d212e038..4c73f384386 100644 --- a/usr.bin/cvs/rcsparse.c +++ b/usr.bin/cvs/rcsparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsparse.c,v 1.6 2012/02/04 21:22:32 tobias Exp $ */ +/* $OpenBSD: rcsparse.c,v 1.7 2013/06/03 17:04:35 jcs Exp $ */ /* * Copyright (c) 2010 Tobias Stoeckmann <tobias@openbsd.org> * @@ -107,6 +107,7 @@ static const struct rcs_keyword keywords[] = { { "branch", RCS_TOK_BRANCH}, { "branches", RCS_TOK_BRANCHES}, { "comment", RCS_TOK_COMMENT}, + { "commitid", RCS_TOK_COMMITID}, { "date", RCS_TOK_DATE}, { "desc", RCS_TOK_DESC}, { "expand", RCS_TOK_EXPAND}, @@ -151,6 +152,7 @@ static int rcsparse_string(RCSFILE *, int); static int rcsparse_token(RCSFILE *, int); static void rcsparse_warnx(RCSFILE *, char *, ...); static int valid_login(char *); +static int valid_commitid(char *); /* * head [REVISION]; @@ -528,7 +530,7 @@ rcsparse_commitid(RCSFILE *rfp, struct rcs_pdata *pdp) if (rcsparse_token(rfp, RCS_TYPE_COMMITID) != RCS_TYPE_COMMITID) return (1); - /* XXX - do something with commitid */ + pdp->rp_delta->rd_commitid = pdp->rp_value.str; return (rcsparse_token(rfp, RCS_TOK_SCOLON) != RCS_TOK_SCOLON); } @@ -989,7 +991,12 @@ rcsparse_token(RCSFILE *rfp, int allowed) switch (allowed) { case RCS_TYPE_COMMITID: - /* XXX validate commitid */ + if (!valid_commitid(pdp->rp_buf)) { + rcsparse_warnx(rfp, "invalid commitid \"%s\"", + pdp->rp_buf); + return (0); + } + pdp->rp_value.str = xstrdup(pdp->rp_buf); break; case RCS_TYPE_LOGIN: if (!valid_login(pdp->rp_buf)) { @@ -1227,6 +1234,21 @@ valid_login(char *login_name) } static int +valid_commitid(char *commitid) +{ + unsigned char *cp; + + /* A-Za-z0-9 */ + for (cp = commitid; *cp ; cp++) { + if (!isalnum(*cp)) + return 0; + } + if ((char *)cp - commitid > RCS_COMMITID_MAXLEN) + return 0; + return 1; +} + +static int kw_cmp(const void *k, const void *e) { return (strcmp(k, ((const struct rcs_keyword *)e)->k_name)); |