diff options
-rw-r--r-- | usr.bin/rcs/ci.c | 16 | ||||
-rw-r--r-- | usr.bin/rcs/diff3.c | 42 | ||||
-rw-r--r-- | usr.bin/rcs/rcs.c | 73 | ||||
-rw-r--r-- | usr.bin/rcs/rcsdiff.c | 30 |
4 files changed, 72 insertions, 89 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c index 4a4d06e7aab..cbadf6db726 100644 --- a/usr.bin/rcs/ci.c +++ b/usr.bin/rcs/ci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ci.c,v 1.167 2006/04/29 06:32:00 ray Exp $ */ +/* $OpenBSD: ci.c,v 1.168 2006/05/04 07:06:58 xsa Exp $ */ /* * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -329,7 +329,7 @@ checkin_main(int argc, char **argv) static char * checkin_diff_file(struct checkin_params *pb) { - char path1[MAXPATHLEN], path2[MAXPATHLEN]; + char *path1, *path2; BUF *b1, *b2, *b3; char rbuf[64], *deltatext; @@ -352,17 +352,13 @@ checkin_diff_file(struct checkin_params *pb) goto out; } - if (strlcpy(path1, rcs_tmpdir, sizeof(path1)) >= sizeof(path1) || - strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1)) >= sizeof(path1)) - errx(1, "path truncated"); + (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b1, path1, 0600); rcs_buf_free(b1); b1 = NULL; - if (strlcpy(path2, rcs_tmpdir, sizeof(path2)) >= sizeof(path2) || - strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2)) >= sizeof(path2)) - errx(1, "path truncated"); + (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b2, path2, 0600); rcs_buf_free(b2); @@ -382,6 +378,10 @@ out: rcs_buf_free(b2); if (b3 != NULL) rcs_buf_free(b3); + if (path1 != NULL) + xfree(path1); + if (path2 != NULL) + xfree(path2); return (deltatext); } diff --git a/usr.bin/rcs/diff3.c b/usr.bin/rcs/diff3.c index 1b43b8b8691..8e2c4ae9429 100644 --- a/usr.bin/rcs/diff3.c +++ b/usr.bin/rcs/diff3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff3.c,v 1.4 2006/05/03 07:10:39 xsa Exp $ */ +/* $OpenBSD: diff3.c,v 1.5 2006/05/04 07:06:58 xsa Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -72,7 +72,7 @@ static const char copyright[] = #ifndef lint static const char rcsid[] = - "$OpenBSD: diff3.c,v 1.4 2006/05/03 07:10:39 xsa Exp $"; + "$OpenBSD: diff3.c,v 1.5 2006/05/04 07:06:58 xsa Exp $"; #endif /* not lint */ #include "includes.h" @@ -159,8 +159,7 @@ rcs_diff3(RCSFILE *rf, char *workfile, RCSNUM *rev1, RCSNUM *rev2, int verbose) int argc; char *data, *patch; char *argv[5], r1[16], r2[16]; - char path1[MAXPATHLEN], path2[MAXPATHLEN], path3[MAXPATHLEN]; - char dp13[MAXPATHLEN], dp23[MAXPATHLEN]; + char *dp13, *dp23, *path1, *path2, *path3; BUF *b1, *b2, *b3, *d1, *d2, *diffb; b1 = b2 = b3 = d1 = d2 = diffb = NULL; @@ -185,17 +184,9 @@ rcs_diff3(RCSFILE *rf, char *workfile, RCSNUM *rev1, RCSNUM *rev2, int verbose) d2 = rcs_buf_alloc((size_t)128, BUF_AUTOEXT); diffb = rcs_buf_alloc((size_t)128, BUF_AUTOEXT); - if (strlcpy(path1, rcs_tmpdir, sizeof(path1)) >= sizeof(path1) || - strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1)) >= sizeof(path1)) - errx(1, "rcs_diff3: string truncated"); - - if (strlcpy(path2, rcs_tmpdir, sizeof(path2)) >= sizeof(path2) || - strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2)) >= sizeof(path2)) - errx(1, "rcs_diff3: string truncated"); - - if (strlcpy(path3, rcs_tmpdir, sizeof(path3)) >= sizeof(path3) || - strlcat(path3, "/diff3.XXXXXXXXXX", sizeof(path3)) >= sizeof(path3)) - errx(1, "rcs_diff3: string truncated"); + (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); + (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); + (void)xasprintf(&path3, "%s/diff3.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b1, path1, 0600); rcs_buf_write_stmp(b2, path2, 0600); @@ -207,19 +198,13 @@ rcs_diff3(RCSFILE *rf, char *workfile, RCSNUM *rev1, RCSNUM *rev2, int verbose) rcs_diffreg(path1, path3, d1); rcs_diffreg(path2, path3, d2); - if (strlcpy(dp13, rcs_tmpdir, sizeof(dp13)) >= sizeof(dp13) || - strlcat(dp13, "/d13.XXXXXXXXXX" , sizeof(dp13)) >= sizeof(dp13)) - errx(1, "rcs_diff3: string truncated"); - + (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(d1, dp13, 0600); rcs_buf_free(d1); d1 = NULL; - if (strlcpy(dp23, rcs_tmpdir, sizeof(dp23)) >= sizeof(dp23) || - strlcat(dp23, "/d23.XXXXXXXXXX", sizeof(dp23)) >= sizeof(dp23)) - errx(1, "rcs_diff3: string truncated"); - + (void)xasprintf(&dp23, "%s/d23.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(d2, dp23, 0600); rcs_buf_free(d2); @@ -277,6 +262,17 @@ out: (void)unlink(dp13); (void)unlink(dp23); + if (path1 != NULL) + xfree(path1); + if (path2 != NULL) + xfree(path2); + if (path3 != NULL) + xfree(path3); + if (dp13 != NULL) + xfree(dp13); + if (dp23 != NULL) + xfree(dp23); + return (diffb); } diff --git a/usr.bin/rcs/rcs.c b/usr.bin/rcs/rcs.c index 5721b2b211c..74c8fecfe6d 100644 --- a/usr.bin/rcs/rcs.c +++ b/usr.bin/rcs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.6 2006/05/01 18:17:39 niallo Exp $ */ +/* $OpenBSD: rcs.c,v 1.7 2006/05/04 07:06:58 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -358,7 +358,7 @@ int rcs_write(RCSFILE *rfp) { FILE *fp; - char buf[1024], numbuf[64], fn[20] = ""; + char buf[1024], numbuf[64], *fn; void *bp; struct rcs_access *ap; struct rcs_sym *symp; @@ -367,9 +367,10 @@ rcs_write(RCSFILE *rfp) struct rcs_lock *lkp; ssize_t nread, nwritten; size_t len; - int fd, from_fd, to_fd; + int fd, from_fd, to_fd, ret; from_fd = to_fd = fd = -1; + ret = -1; if (rfp->rf_flags & RCS_SYNCED) return (0); @@ -377,8 +378,8 @@ rcs_write(RCSFILE *rfp) /* Write operations need the whole file parsed */ rcs_parse_deltatexts(rfp, NULL); - if (strlcpy(fn, "/tmp/rcs.XXXXXXXXXX", sizeof(fn)) >= sizeof(fn)) - errx(1, "rcs_write: string truncated"); + (void)xasprintf(&fn, "%s/rcs.XXXXXXXXXX", rcs_tmpdir); + if ((fd = mkstemp(fn)) == -1) err(1, "%s", fn); @@ -514,16 +515,14 @@ rcs_write(RCSFILE *rfp) } if ((from_fd = open(fn, O_RDONLY)) == -1) { - warn("failed to open `%s'", - rfp->rf_path); - return (-1); + warn("failed to open `%s'", rfp->rf_path); + goto out; } if ((to_fd = open(rfp->rf_path, O_WRONLY|O_TRUNC|O_CREAT)) == -1) { warn("failed to open `%s'", fn); - close(from_fd); - return (-1); + goto out; } bp = xmalloc(MAXBSIZE); @@ -541,34 +540,37 @@ rcs_write(RCSFILE *rfp) err: if (unlink(rfp->rf_path) == -1) warn("failed to unlink `%s'", rfp->rf_path); - close(from_fd); - close(to_fd); xfree(bp); - return (-1); + goto out; } - - close(from_fd); - close(to_fd); xfree(bp); if (unlink(fn) == -1) { warn("failed to unlink `%s'", fn); - return (-1); + goto out; } } else { warn("failed to access temp RCS output file"); - return (-1); + goto out; } } if (chmod(rfp->rf_path, rfp->rf_mode) == -1) { warn("failed to chmod `%s'", rfp->rf_path); - return (-1); + goto out; } rfp->rf_flags |= RCS_SYNCED; - return (0); + ret = 0; +out: + (void)close(from_fd); + (void)close(to_fd); + + if (fn != NULL) + xfree(fn); + + return (ret); } /* @@ -1341,14 +1343,10 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, int rcs_rev_remove(RCSFILE *rf, RCSNUM *rev) { - size_t len; - char *tmpdir; - char *newdeltatext, path_tmp1[MAXPATHLEN], path_tmp2[MAXPATHLEN]; + char *newdeltatext, *path_tmp1, *path_tmp2; struct rcs_delta *rdp, *prevrdp, *nextrdp; BUF *nextbuf, *prevbuf, *newdiff; - tmpdir = rcs_tmpdir; - if (rev == RCS_HEAD_REV) rev = rf->rf_head; @@ -1383,27 +1381,11 @@ rcs_rev_remove(RCSFILE *rf, RCSNUM *rev) newdiff = rcs_buf_alloc(64, BUF_AUTOEXT); /* calculate new diff */ - len = strlcpy(path_tmp1, tmpdir, sizeof(path_tmp1)); - if (len >= sizeof(path_tmp1)) - errx(1, "path truncation in rcs_rev_remove"); - - len = strlcat(path_tmp1, "/diff1.XXXXXXXXXX", - sizeof(path_tmp1)); - if (len >= sizeof(path_tmp1)) - errx(1, "path truncation in rcs_rev_remove"); - + (void)xasprintf(&path_tmp1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(nextbuf, path_tmp1, 0600); rcs_buf_free(nextbuf); - len = strlcpy(path_tmp2, tmpdir, sizeof(path_tmp2)); - if (len >= sizeof(path_tmp2)) - errx(1, "path truncation in rcs_rev_remove"); - - len = strlcat(path_tmp2, "/diff2.XXXXXXXXXX", - sizeof(path_tmp2)); - if (len >= sizeof(path_tmp2)) - errx(1, "path truncation in rcs_rev_remove"); - + (void)xasprintf(&path_tmp2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(prevbuf, path_tmp2, 0600); rcs_buf_free(prevbuf); @@ -1444,6 +1426,11 @@ rcs_rev_remove(RCSFILE *rf, RCSNUM *rev) if (newdeltatext != NULL) xfree(newdeltatext); + if (path_tmp1 != NULL) + xfree(path_tmp1); + if (path_tmp2 != NULL) + xfree(path_tmp2); + return (0); } diff --git a/usr.bin/rcs/rcsdiff.c b/usr.bin/rcs/rcsdiff.c index 87a2929e426..1964b99b458 100644 --- a/usr.bin/rcs/rcsdiff.c +++ b/usr.bin/rcs/rcsdiff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsdiff.c,v 1.59 2006/04/29 05:31:28 ray Exp $ */ +/* $OpenBSD: rcsdiff.c,v 1.60 2006/05/04 07:06:58 xsa Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -185,7 +185,7 @@ rcsdiff_file(RCSFILE *file, RCSNUM *rev, const char *filename) int ret, fd; time_t t; struct stat st; - char path1[MAXPATHLEN], path2[MAXPATHLEN]; + char *path1, *path2; BUF *b1, *b2; char rbuf[64]; struct tm *tb; @@ -235,9 +235,7 @@ rcsdiff_file(RCSFILE *file, RCSNUM *rev, const char *filename) tv2[0].tv_sec = t; tv2[1].tv_sec = t; - if (strlcpy(path1, rcs_tmpdir, sizeof(path1)) >= sizeof(path1) || - strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1)) >= sizeof(path1)) - errx(1, "path too long"); + (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b1, path1, 0600); rcs_buf_free(b1); @@ -246,9 +244,7 @@ rcsdiff_file(RCSFILE *file, RCSNUM *rev, const char *filename) if (utimes(path1, (const struct timeval *)&tv) < 0) warn("utimes"); - if (strlcpy(path2, rcs_tmpdir, sizeof(path2)) >= sizeof(path2) || - strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2)) >= sizeof(path2)) - errx(1, "path too long"); + (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b2, path2, 0600); rcs_buf_free(b2); @@ -267,6 +263,10 @@ out: rcs_buf_free(b1); if (b2 != NULL) rcs_buf_free(b2); + if (path1 != NULL) + xfree(path1); + if (path2 != NULL) + xfree(path2); return (ret); } @@ -275,7 +275,7 @@ static int rcsdiff_rev(RCSFILE *file, RCSNUM *rev1, RCSNUM *rev2) { int ret; - char path1[MAXPATHLEN], path2[MAXPATHLEN]; + char *path1, *path2; BUF *b1, *b2; char rbuf1[64], rbuf2[64]; struct timeval tv[2], tv2[2]; @@ -317,9 +317,7 @@ rcsdiff_rev(RCSFILE *file, RCSNUM *rev1, RCSNUM *rev2) if (!(flags & QUIET)) fprintf(stderr, "%s -r%s -r%s\n", diffargs, rbuf1, rbuf2); - if (strlcpy(path1, rcs_tmpdir, sizeof(path1)) >= sizeof(path1) || - strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1)) >= sizeof(path1)) - errx(1, "path too long"); + (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b1, path1, 0600); rcs_buf_free(b1); @@ -328,9 +326,7 @@ rcsdiff_rev(RCSFILE *file, RCSNUM *rev1, RCSNUM *rev2) if (utimes(path1, (const struct timeval *)&tv) < 0) warn("utimes"); - if (strlcpy(path2, rcs_tmpdir, sizeof(path2)) >= sizeof(path2) || - strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2)) >= sizeof(path2)) - errx(1, "path too long"); + (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); rcs_buf_write_stmp(b2, path2, 0600); rcs_buf_free(b2); @@ -347,6 +343,10 @@ out: rcs_buf_free(b1); if (b2 != NULL) rcs_buf_free(b2); + if (path1 != NULL) + xfree(path1); + if (path2 != NULL) + xfree(path2); return (ret); } |