diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2007-02-17 18:23:44 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2007-02-17 18:23:44 +0000 |
commit | 9384a10810c060382177f59d1025e145cd63e903 (patch) | |
tree | 630c82f79a631a855e6a3959d5ae96e602671c9a /usr.bin | |
parent | 574a3af15cc4802db79e1bab0f6fb86a1be67e35 (diff) |
cvs_path_cat() removal since we can now easily handle that
functionality w/ xsnprintf(); Initial diff started by thib@.
OK thib@ joris@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/add.c | 12 | ||||
-rw-r--r-- | usr.bin/cvs/admin.c | 5 | ||||
-rw-r--r-- | usr.bin/cvs/checkout.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/client.c | 24 | ||||
-rw-r--r-- | usr.bin/cvs/config.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.c | 15 | ||||
-rw-r--r-- | usr.bin/cvs/edit.c | 12 | ||||
-rw-r--r-- | usr.bin/cvs/entries.c | 24 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/init.c | 12 | ||||
-rw-r--r-- | usr.bin/cvs/repository.c | 17 | ||||
-rw-r--r-- | usr.bin/cvs/server.c | 20 | ||||
-rw-r--r-- | usr.bin/cvs/update.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 65 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 3 |
15 files changed, 80 insertions, 157 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c index d536833b4b4..8ef66e323c7 100644 --- a/usr.bin/cvs/add.c +++ b/usr.bin/cvs/add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: add.c,v 1.75 2007/02/09 03:49:15 joris Exp $ */ +/* $OpenBSD: add.c,v 1.76 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> @@ -182,9 +182,8 @@ add_directory(struct cvs_file *cf) /* Let's see if we have any per-directory tags first. */ cvs_parse_tagfile(cf->file_wd, &tag, &date, &nb); - if (cvs_path_cat(cf->file_path, CVS_PATH_CVSDIR, - entry, MAXPATHLEN) >= MAXPATHLEN) - fatal("add_directory: truncation"); + (void)xsnprintf(entry, MAXPATHLEN, "%s/%s", + cf->file_path, CVS_PATH_CVSDIR); if (stat(entry, &st) != -1) { if (!S_ISDIR(st.st_mode)) { @@ -204,9 +203,8 @@ add_directory(struct cvs_file *cf) cvs_get_repository_name(cf->file_wd, repo, MAXPATHLEN); - if (cvs_path_cat(repo, cf->file_name, entry, - MAXPATHLEN) >= MAXPATHLEN) - fatal("add_directory: truncation"); + (void)xsnprintf(entry, MAXPATHLEN, "%s/%s", + repo, cf->file_name); cvs_mkadmin(cf->file_path, current_cvsroot->cr_dir, entry, tag, date, nb); diff --git a/usr.bin/cvs/admin.c b/usr.bin/cvs/admin.c index c79a6a6d593..b172543d823 100644 --- a/usr.bin/cvs/admin.c +++ b/usr.bin/cvs/admin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: admin.c,v 1.48 2007/02/09 03:49:15 joris Exp $ */ +/* $OpenBSD: admin.c,v 1.49 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005 Joris Vink <joris@openbsd.org> @@ -234,8 +234,7 @@ cvs_admin_local(struct cvs_file *cf) cvs_get_repository_path(d, repo, MAXPATHLEN); - if (cvs_path_cat(repo, f, fpath, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_admin_local: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", repo, f); if (strlcat(fpath, RCS_FILE_EXT, MAXPATHLEN) >= MAXPATHLEN) fatal("cvs_admin_local: truncation"); diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 1f4d42a8e30..4a49c8fb1bf 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.89 2007/01/31 21:07:35 xsa Exp $ */ +/* $OpenBSD: checkout.c,v 1.90 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -155,9 +155,8 @@ checkout_check_repository(int argc, char **argv) } for (i = 0; i < argc; i++) { - if (cvs_path_cat(current_cvsroot->cr_dir, argv[i], repo, - sizeof(repo)) >= sizeof(repo)) - fatal("checkout_check_repository: truncation"); + (void)xsnprintf(repo, sizeof(repo), "%s/%s", + current_cvsroot->cr_dir, argv[i]); if (stat(repo, &st) == -1) { cvs_log(LP_ERR, "cannot find module `%s' - ignored", diff --git a/usr.bin/cvs/client.c b/usr.bin/cvs/client.c index 953ed80cbe7..e5bab2ac8c5 100644 --- a/usr.bin/cvs/client.c +++ b/usr.bin/cvs/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.57 2007/01/31 21:07:35 xsa Exp $ */ +/* $OpenBSD: client.c,v 1.58 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -370,9 +370,8 @@ cvs_client_senddir(const char *dir) cvs_client_send_request("Directory %s\n%s", dir, repo); - if (cvs_path_cat(dir, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >= - MAXPATHLEN) - fatal("cvs_client_senddir: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + dir, CVS_PATH_STATICENTRIES); if (stat(fpath, &st) == 0 && (st.st_mode & (S_IRUSR|S_IRGRP|S_IROTH))) cvs_client_send_request("Static-directory"); @@ -780,9 +779,8 @@ cvs_client_set_static_directory(char *data) dir = cvs_remote_input(); xfree(dir); - if (cvs_path_cat(data, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >= - MAXPATHLEN) - fatal("cvs_client_set_static_directory: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + data, CVS_PATH_STATICENTRIES); if ((fp = fopen(fpath, "w+")) == NULL) { cvs_log(LP_ERRNO, "%s", fpath); @@ -804,9 +802,8 @@ cvs_client_clear_static_directory(char *data) dir = cvs_remote_input(); xfree(dir); - if (cvs_path_cat(data, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >= - MAXPATHLEN) - fatal("cvs_client_clear_static_directory: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + data, CVS_PATH_STATICENTRIES); (void)cvs_unlink(fpath); } @@ -826,8 +823,7 @@ cvs_client_set_sticky(char *data) xfree(dir); tag = cvs_remote_input(); - if (cvs_path_cat(data, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_client_clear_sticky: truncation"); + (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG); if ((fp = fopen(tagpath, "w+")) == NULL) { cvs_log(LP_ERRNO, "%s", tagpath); @@ -853,9 +849,7 @@ cvs_client_clear_sticky(char *data) dir = cvs_remote_input(); xfree(dir); - if (cvs_path_cat(data, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_client_clear_sticky: truncation"); - + (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG); (void)cvs_unlink(tagpath); } diff --git a/usr.bin/cvs/config.c b/usr.bin/cvs/config.c index 7def6425acc..2436b77f86b 100644 --- a/usr.bin/cvs/config.c +++ b/usr.bin/cvs/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.7 2007/01/25 08:21:08 otto Exp $ */ +/* $OpenBSD: config.c,v 1.8 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -31,9 +31,8 @@ cvs_parse_configfile(void) const char *errstr; char *p, *buf, *lbuf, *opt, *val, fpath[MAXPATHLEN]; - if (cvs_path_cat(current_cvsroot->cr_dir, CVS_PATH_CONFIG, - fpath, sizeof(fpath)) >= sizeof(fpath)) - fatal("cvs_parse_configfile: truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", + current_cvsroot->cr_dir, CVS_PATH_CONFIG); cvs_log(LP_TRACE, "cvs_parse_configfile(%s)", fpath); diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index e866837f4a7..9816851bf79 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.115 2007/02/09 03:30:31 joris Exp $ */ +/* $OpenBSD: cvs.c,v 1.116 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006, 2007 Joris Vink <joris@openbsd.org> * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> @@ -257,9 +257,8 @@ main(int argc, char **argv) return (0); } - if (cvs_path_cat(current_cvsroot->cr_dir, CVS_PATH_ROOT, - fpath, sizeof(fpath)) >= sizeof(fpath)) - fatal("main: truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", + current_cvsroot->cr_dir, CVS_PATH_ROOT); if (stat(fpath, &st) == -1 && cvs_cmdop != CVS_OP_INIT) { if (errno == ENOENT) @@ -396,13 +395,15 @@ static void cvs_read_rcfile(void) { char rcpath[MAXPATHLEN], linebuf[128], *lp, *p; - int linenum = 0; + int i, linenum; size_t len; struct cvs_cmd *cmdp; FILE *fp; - if (cvs_path_cat(cvs_homedir, CVS_PATH_RC, rcpath, sizeof(rcpath)) - >= sizeof(rcpath)) { + linenum = 0; + + i = snprintf(rcpath, MAXPATHLEN, "%s/%s", cvs_homedir, CVS_PATH_RC); + if (i < 0 || i >= MAXPATHLEN) { cvs_log(LP_ERRNO, "%s", rcpath); return; } diff --git a/usr.bin/cvs/edit.c b/usr.bin/cvs/edit.c index 7c8bf893b67..cd562833976 100644 --- a/usr.bin/cvs/edit.c +++ b/usr.bin/cvs/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.32 2007/02/09 03:49:15 joris Exp $ */ +/* $OpenBSD: edit.c,v 1.33 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006, 2007 Xavier Santolaria <xsa@openbsd.org> * @@ -298,9 +298,8 @@ cvs_edit_local(struct cvs_file *cf) if (fchmod(cf->fd, 0644) == -1) fatal("cvs_edit_local: fchmod %s", strerror(errno)); - if (cvs_path_cat(CVS_PATH_BASEDIR, cf->file_name, bfpath, - MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_edit_local: truncation"); + (void)xsnprintf(bfpath, MAXPATHLEN, "%s/%s", + CVS_PATH_BASEDIR, cf->file_name); if (mkdir(CVS_PATH_BASEDIR, 0755) == -1 && errno != EEXIST) fatal("cvs_edit_local: `%s': %s", CVS_PATH_BASEDIR, @@ -335,9 +334,8 @@ cvs_unedit_local(struct cvs_file *cf) cvs_file_classify(cf, NULL); - if (cvs_path_cat(CVS_PATH_BASEDIR, cf->file_name, bfpath, - MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_unedit_local: truncation"); + (void)xsnprintf(bfpath, MAXPATHLEN, "%s/%s", + CVS_PATH_BASEDIR, cf->file_name); if (stat(bfpath, &st) == -1) return; diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c index 18c25e40bb8..d4c93399f72 100644 --- a/usr.bin/cvs/entries.c +++ b/usr.bin/cvs/entries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: entries.c,v 1.72 2007/02/04 06:09:31 joris Exp $ */ +/* $OpenBSD: entries.c,v 1.73 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -38,21 +38,16 @@ cvs_ent_open(const char *dir) ep = (CVSENTRIES *)xmalloc(sizeof(*ep)); memset(ep, 0, sizeof(*ep)); - if (cvs_path_cat(dir, CVS_PATH_ENTRIES, buf, sizeof(buf)) >= - sizeof(buf)) - fatal("cvs_ent_open: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", dir, CVS_PATH_ENTRIES); ep->cef_path = xstrdup(buf); - if (cvs_path_cat(dir, CVS_PATH_BACKUPENTRIES, buf, sizeof(buf)) >= - sizeof(buf)) - fatal("cvs_ent_open: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", + dir, CVS_PATH_BACKUPENTRIES); ep->cef_bpath = xstrdup(buf); - if (cvs_path_cat(dir, CVS_PATH_LOGENTRIES, buf, sizeof(buf)) >= - sizeof(buf)) - fatal("cvs_ent_open: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", dir, CVS_PATH_LOGENTRIES); ep->cef_lpath = xstrdup(buf); @@ -359,7 +354,7 @@ void cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp) { FILE *fp; - int linenum; + int i, linenum; size_t len; char linebuf[128], tagpath[MAXPATHLEN]; @@ -372,7 +367,8 @@ cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp) if (nbp != NULL) *nbp = 0; - if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) + i = snprintf(tagpath, MAXPATHLEN, "%s/%s", dir, CVS_PATH_TAG); + if (i < 0 || i >= MAXPATHLEN) return; if ((fp = fopen(tagpath, "r")) == NULL) { @@ -425,11 +421,13 @@ cvs_write_tagfile(char *dir, char *tag, char *date, int nb) { FILE *fp; char tagpath[MAXPATHLEN]; + int i; if (cvs_noexec == 1) return; - if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) + i = snprintf(tagpath, MAXPATHLEN, "%s/%s", dir, CVS_PATH_TAG); + if (i < 0 || i >= MAXPATHLEN) return; if ((tag != NULL) || (date != NULL)) { diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index 1afd72f0021..fbe1e3d3d03 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.69 2007/02/09 03:49:15 joris Exp $ */ +/* $OpenBSD: import.c,v 1.70 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -128,9 +128,8 @@ cvs_import(int argc, char **argv) return (0); } - if (cvs_path_cat(current_cvsroot->cr_dir, import_repository, - repo, sizeof(repo)) >= sizeof(repo)) - fatal("cvs_import: truncation"); + (void)xsnprintf(repo, sizeof(repo), "%s/%s", + current_cvsroot->cr_dir, import_repository); if (cvs_noexec != 1) { if (mkdir(repo, 0755) == -1 && errno != EEXIST) diff --git a/usr.bin/cvs/init.c b/usr.bin/cvs/init.c index 30875e6b1f6..97983700aca 100644 --- a/usr.bin/cvs/init.c +++ b/usr.bin/cvs/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.30 2007/02/06 17:34:06 xsa Exp $ */ +/* $OpenBSD: init.c,v 1.31 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> @@ -103,17 +103,15 @@ cvs_init_local(void) init_mkdir(current_cvsroot->cr_dir, 0777); for (i = 0; i < INIT_NDIRS; i++) { - if (cvs_path_cat(current_cvsroot->cr_dir, - cvsroot_dirs[i], path, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_init_local: truncation"); + (void)xsnprintf(path, MAXPATHLEN, "%s/%s", + current_cvsroot->cr_dir, cvsroot_dirs[i]); init_mkdir(path, 0777); } for (i = 0; i < INIT_NFILES; i++) { - if (cvs_path_cat(current_cvsroot->cr_dir, - cvsroot_files[i].cf_path, path, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_init_local: truncation"); + (void)xsnprintf(path, MAXPATHLEN, "%s/%s", + current_cvsroot->cr_dir, cvsroot_files[i].cf_path); init_mkfile(path, cvsroot_files[i].cf_content); } diff --git a/usr.bin/cvs/repository.c b/usr.bin/cvs/repository.c index 25b11c917df..df0a7c064f3 100644 --- a/usr.bin/cvs/repository.c +++ b/usr.bin/cvs/repository.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repository.c,v 1.10 2007/02/07 23:47:56 todd Exp $ */ +/* $OpenBSD: repository.c,v 1.11 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -32,8 +32,7 @@ cvs_repository_unlock(const char *repo) cvs_log(LP_TRACE, "cvs_repository_unlock(%s)", repo); - if (cvs_path_cat(repo, CVS_LOCK, fpath, sizeof(fpath)) >= sizeof(fpath)) - fatal("cvs_repository_unlock: truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", repo, CVS_LOCK); /* XXX - this ok? */ cvs_worklist_run(&repo_locks, cvs_worklist_unlink); @@ -52,8 +51,7 @@ cvs_repository_lock(const char *repo) cvs_log(LP_TRACE, "cvs_repository_lock(%s)", repo); - if (cvs_path_cat(repo, CVS_LOCK, fpath, sizeof(fpath)) >= sizeof(fpath)) - fatal("cvs_repository_unlock: truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", repo, CVS_LOCK); for (i = 0; i < CVS_LOCK_TRIES; i++) { if (cvs_quit) @@ -108,13 +106,8 @@ cvs_repository_getdir(const char *dir, const char *wdir, if (cvs_file_chkign(dp->d_name)) continue; - if (cvs_path_cat(wdir, dp->d_name, - fpath, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_repository_getdir: truncation"); - - if (cvs_path_cat(dir, dp->d_name, - rpath, MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_repository_getdir: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", wdir, dp->d_name); + (void)xsnprintf(rpath, MAXPATHLEN, "%s/%s", dir, dp->d_name); /* * nfs and afs will show d_type as DT_UNKNOWN diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 985cc680dd2..e59dd32b385 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.53 2007/01/31 21:07:36 xsa Exp $ */ +/* $OpenBSD: server.c,v 1.54 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -219,9 +219,8 @@ cvs_server_static_directory(char *data) FILE *fp; char fpath[MAXPATHLEN]; - if (cvs_path_cat(server_currentdir, CVS_PATH_STATICENTRIES, fpath, - MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_server_static_directory: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + server_currentdir, CVS_PATH_STATICENTRIES); if ((fp = fopen(fpath, "w+")) == NULL) { cvs_log(LP_ERRNO, "%s", fpath); @@ -236,9 +235,8 @@ cvs_server_sticky(char *data) FILE *fp; char tagpath[MAXPATHLEN]; - if (cvs_path_cat(server_currentdir, CVS_PATH_TAG, tagpath, - MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_server_sticky: truncation"); + (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", + server_currentdir, CVS_PATH_TAG); if ((fp = fopen(tagpath, "w+")) == NULL) { cvs_log(LP_ERRNO, "%s", tagpath); @@ -365,9 +363,7 @@ cvs_server_modified(char *data) fatal("cvs_server_modified: %s", errstr); xfree(len); - if (cvs_path_cat(server_currentdir, data, fpath, MAXPATHLEN) >= - MAXPATHLEN) - fatal("cvs_server_modified: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data); if ((fd = open(fpath, O_WRONLY | O_CREAT | O_TRUNC)) == -1) fatal("cvs_server_modified: %s: %s", fpath, strerror(errno)); @@ -394,9 +390,7 @@ cvs_server_unchanged(char *data) struct cvs_ent *ent; struct timeval tv[2]; - if (cvs_path_cat(server_currentdir, data, fpath, MAXPATHLEN) >= - MAXPATHLEN) - fatal("cvs_server_unchanged: truncation"); + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data); if ((fd = open(fpath, O_RDWR | O_CREAT | O_TRUNC)) == -1) fatal("cvs_server_unchanged: %s: %s", fpath, strerror(errno)); diff --git a/usr.bin/cvs/update.c b/usr.bin/cvs/update.c index 9783ff0bc55..7652018183e 100644 --- a/usr.bin/cvs/update.c +++ b/usr.bin/cvs/update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: update.c,v 1.95 2007/02/09 16:46:26 joris Exp $ */ +/* $OpenBSD: update.c,v 1.96 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -185,9 +185,8 @@ cvs_update_leavedir(struct cvs_file *cf) cvs_log(LP_TRACE, "cvs_update_leavedir(%s)", cf->file_path); if (cvs_cmdop == CVS_OP_EXPORT) { - if (cvs_path_cat(cf->file_path, CVS_PATH_CVSDIR, export, - MAXPATHLEN) >= MAXPATHLEN) - fatal("cvs_update_leavedir: truncation"); + (void)xsnprintf(export, MAXPATHLEN, "%s/%s", + cf->file_path, CVS_PATH_CVSDIR); /* XXX */ if (cvs_rmdir(export) == -1) diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index d6964bade62..d61a79f83df 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.104 2007/02/07 23:47:56 todd Exp $ */ +/* $OpenBSD: util.c,v 1.105 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -463,7 +463,6 @@ int cvs_rmdir(const char *path) { int type, ret = -1; - size_t len; DIR *dirp; struct dirent *ent; struct stat st; @@ -485,9 +484,8 @@ cvs_rmdir(const char *path) !strcmp(ent->d_name, "..")) continue; - len = cvs_path_cat(path, ent->d_name, fpath, sizeof(fpath)); - if (len >= sizeof(fpath)) - fatal("cvs_rmdir: path truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", + path, ent->d_name); if (ent->d_type == DT_UNKNOWN) { if (lstat(fpath, &st) == -1) @@ -543,46 +541,13 @@ done: return (ret); } -/* - * cvs_path_cat() - * - * Concatenate the two paths <base> and <end> and store the generated path - * into the buffer <dst>, which can accept up to <dlen> bytes, including the - * NUL byte. The result is guaranteed to be NUL-terminated. - * Returns the number of bytes necessary to store the full resulting path, - * not including the NUL byte (a value equal to or larger than <dlen> - * indicates truncation). - */ -size_t -cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen) -{ - size_t len; - - len = strlcpy(dst, base, dlen); - if (len >= dlen - 1) { - errno = ENAMETOOLONG; - fatal("overflow in cvs_path_cat"); - } else { - dst[len] = '/'; - dst[len + 1] = '\0'; - len = strlcat(dst, end, dlen); - if (len >= dlen) { - errno = ENAMETOOLONG; - cvs_log(LP_ERR, "%s", dst); - } - } - - return (len); -} - void cvs_get_repository_path(const char *dir, char *dst, size_t len) { char buf[MAXPATHLEN]; cvs_get_repository_name(dir, buf, sizeof(buf)); - if (cvs_path_cat(current_cvsroot->cr_dir, buf, dst, len) >= len) - fatal("cvs_get_repository_path: truncation"); + (void)xsnprintf(dst, len, "%s/%s", current_cvsroot->cr_dir, buf); } void @@ -591,9 +556,8 @@ cvs_get_repository_name(const char *dir, char *dst, size_t len) FILE *fp; char *s, fpath[MAXPATHLEN]; - if (cvs_path_cat(dir, CVS_PATH_REPOSITORY, - fpath, sizeof(fpath)) >= sizeof(fpath)) - fatal("cvs_get_repository_name: truncation"); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", + dir, CVS_PATH_REPOSITORY); if ((fp = fopen(fpath, "r")) != NULL) { if ((fgets(dst, len, fp)) == NULL) @@ -633,7 +597,6 @@ cvs_mkadmin(const char *path, const char *root, const char *repo, char *tag, char *date, int nb) { FILE *fp; - size_t len; struct stat st; char buf[MAXPATHLEN]; @@ -642,9 +605,7 @@ cvs_mkadmin(const char *path, const char *root, const char *repo, path, root, repo, (tag != NULL) ? tag : "", (date != NULL) ? date : "", nb); - len = cvs_path_cat(path, CVS_PATH_CVSDIR, buf, sizeof(buf)); - if (len >= sizeof(buf)) - fatal("cvs_mkadmin: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", path, CVS_PATH_CVSDIR); if (stat(buf, &st) != -1) return; @@ -652,9 +613,7 @@ cvs_mkadmin(const char *path, const char *root, const char *repo, if (mkdir(buf, 0755) == -1 && errno != EEXIST) fatal("cvs_mkadmin: %s: %s", buf, strerror(errno)); - len = cvs_path_cat(path, CVS_PATH_ROOTSPEC, buf, sizeof(buf)); - if (len >= sizeof(buf)) - fatal("cvs_mkadmin: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", path, CVS_PATH_ROOTSPEC); if ((fp = fopen(buf, "w")) == NULL) fatal("cvs_mkadmin: %s: %s", buf, strerror(errno)); @@ -662,9 +621,7 @@ cvs_mkadmin(const char *path, const char *root, const char *repo, fprintf(fp, "%s\n", root); (void)fclose(fp); - len = cvs_path_cat(path, CVS_PATH_REPOSITORY, buf, sizeof(buf)); - if (len >= sizeof(buf)) - fatal("cvs_mkadmin: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", path, CVS_PATH_REPOSITORY); if ((fp = fopen(buf, "w")) == NULL) fatal("cvs_mkadmin: %s: %s", buf, strerror(errno)); @@ -672,9 +629,7 @@ cvs_mkadmin(const char *path, const char *root, const char *repo, fprintf(fp, "%s\n", repo); (void)fclose(fp); - len = cvs_path_cat(path, CVS_PATH_ENTRIES, buf, sizeof(buf)); - if (len >= sizeof(buf)) - fatal("cvs_mkadmin: truncation"); + (void)xsnprintf(buf, sizeof(buf), "%s/%s", path, CVS_PATH_ENTRIES); if ((fp = fopen(buf, "w")) == NULL) fatal("cvs_mkadmin: %s: %s", buf, strerror(errno)); diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index cadf3ac0ddc..93dcf79be41 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.15 2007/01/26 11:19:44 joris Exp $ */ +/* $OpenBSD: util.h,v 1.16 2007/02/17 18:23:43 xsa Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -44,7 +44,6 @@ int cvs_unlink(const char *); int cvs_rmdir(const char *); char **cvs_makeargv(const char *, int *); void cvs_freeargv(char **, int); -size_t cvs_path_cat(const char *, const char *, char *, size_t); u_int cvs_revision_select(RCSFILE *, char *); struct cvs_line { |