summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/rcs.c
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2020-10-19 19:51:21 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2020-10-19 19:51:21 +0000
commit9941cc9efda213d32111bbe22780fe9e4a865220 (patch)
tree8b03b6a48936d0ef6aff5ca956daa0e5f1eda6d9 /usr.bin/cvs/rcs.c
parent5454133fac5af90d436ece81c7fd015ab3c2d867 (diff)
Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer. ok florian@ millert@
Diffstat (limited to 'usr.bin/cvs/rcs.c')
-rw-r--r--usr.bin/cvs/rcs.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 6b4b6acd243..f4d0fb4f7cc 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.319 2019/06/28 13:35:00 deraadt Exp $ */
+/* $OpenBSD: rcs.c,v 1.320 2020/10/19 19:51:20 naddy Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -2183,8 +2183,8 @@ rcs_kwexp_line(char *rcsfile, struct rcs_delta *rdp, struct rcs_lines *lines,
int kwtype;
u_int j, found;
const u_char *c, *start, *fin, *end;
- char *kwstr;
- char expbuf[256], buf[256];
+ char *kwstr, *rcsfile_basename;
+ char expbuf[256], buf[256], path[PATH_MAX];
size_t clen, kwlen, len, tlen;
kwtype = 0;
@@ -2202,6 +2202,10 @@ rcs_kwexp_line(char *rcsfile, struct rcs_delta *rdp, struct rcs_lines *lines,
/* Final character in buffer. */
fin = c + len - 1;
+ if (strlcpy(path, rcsfile, sizeof(path)) >= sizeof(path))
+ fatal("rcs_kwexp_line: truncation");
+ rcsfile_basename = basename(path);
+
/*
* Keyword formats:
* $Keyword$
@@ -2300,7 +2304,7 @@ rcs_kwexp_line(char *rcsfile, struct rcs_delta *rdp, struct rcs_lines *lines,
if (mode & RCS_KWEXP_VAL) {
if (kwtype & RCS_KW_RCSFILE) {
if (!(kwtype & RCS_KW_FULLPATH))
- (void)strlcat(expbuf, basename(rcsfile),
+ (void)strlcat(expbuf, rcsfile_basename,
sizeof(expbuf));
else
(void)strlcat(expbuf, rcsfile,
@@ -2376,7 +2380,7 @@ rcs_kwexp_line(char *rcsfile, struct rcs_delta *rdp, struct rcs_lines *lines,
/* Log line */
if (!(kwtype & RCS_KW_FULLPATH))
(void)strlcat(expbuf,
- basename(rcsfile), sizeof(expbuf));
+ rcsfile_basename, sizeof(expbuf));
else
(void)strlcat(expbuf, rcsfile,
sizeof(expbuf));