summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/cvs/rcs.c47
-rw-r--r--usr.bin/cvs/rcs.h5
2 files changed, 50 insertions, 2 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index b259db4ff1a..602be5f42ea 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.46 2005/04/12 14:40:19 jfb Exp $ */
+/* $OpenBSD: rcs.c,v 1.47 2005/04/19 19:22:31 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -111,6 +111,10 @@ struct rcs_foo {
#define RCS_TOKLEN(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_tlen
+
+/* invalid characters in RCS symbol names */
+static const char rcs_sym_invch[] = "$,.:;@";
+
#ifdef notyet
static struct rcs_kfl {
char rk_char;
@@ -594,6 +598,11 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum)
{
struct rcs_sym *symp;
+ if (!rcs_sym_check(sym)) {
+ rcs_errno = RCS_ERR_BADSYM;
+ return (NULL);
+ }
+
/* first look for duplication */
TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) {
if (strcmp(symp->rs_name, sym) == 0) {
@@ -643,6 +652,11 @@ rcs_sym_remove(RCSFILE *file, const char *sym)
{
struct rcs_sym *symp;
+ if (!rcs_sym_check(sym)) {
+ rcs_errno = RCS_ERR_BADSYM;
+ return (NULL);
+ }
+
TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
if (strcmp(symp->rs_name, sym) == 0)
break;
@@ -676,6 +690,11 @@ rcs_sym_getrev(RCSFILE *file, const char *sym)
RCSNUM *num;
struct rcs_sym *symp;
+ if (!rcs_sym_check(sym)) {
+ rcs_errno = RCS_ERR_BADSYM;
+ return (NULL);
+ }
+
num = NULL;
TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
if (strcmp(symp->rs_name, sym) == 0)
@@ -693,6 +712,32 @@ rcs_sym_getrev(RCSFILE *file, const char *sym)
}
/*
+ * rcs_sym_check()
+ *
+ * Check the RCS symbol name <sym> for any unsupported characters.
+ * Returns 1 if the tag is correct, 0 if it isn't valid.
+ */
+int
+rcs_sym_check(const char *sym)
+{
+ int ret;
+ const char *cp;
+
+ ret = 1;
+ cp = sym;
+ if (!isalpha(*cp++))
+ return (0);
+
+ for (; *cp != '\0'; cp++)
+ if (!isgraph(*cp) || (strchr(rcs_sym_invch, *cp) != NULL)) {
+ ret = 0;
+ break;
+ }
+
+ return (ret);
+}
+
+/*
* rcs_lock_getmode()
*
* Retrieve the locking mode of the RCS file <file>.
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index 3b66a8b28b6..80bab8b715d 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.21 2005/04/13 15:50:49 jfb Exp $ */
+/* $OpenBSD: rcs.h,v 1.22 2005/04/19 19:22:31 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -96,6 +96,8 @@
#define RCS_ERR_NOENT 1
#define RCS_ERR_DUPENT 2
#define RCS_ERR_BADNUM 3
+#define RCS_ERR_BADSYM 4
+#define RCS_ERR_PARSE 5
typedef struct rcs_num {
@@ -188,6 +190,7 @@ int rcs_access_check (RCSFILE *, const char *);
int rcs_sym_add (RCSFILE *, const char *, RCSNUM *);
int rcs_sym_remove (RCSFILE *, const char *);
RCSNUM* rcs_sym_getrev (RCSFILE *, const char *);
+int rcs_sym_check (const char *);
int rcs_lock_getmode (RCSFILE *);
int rcs_lock_setmode (RCSFILE *, int);
int rcs_lock_add (RCSFILE *, const char *, RCSNUM *);