summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2006-01-25 08:15:06 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2006-01-25 08:15:06 +0000
commitf5e7c41f1a83f98bbc702d6dfbae12805b4a321f (patch)
treebd9daa4dafc25ffc66d1b64185acf999f2a50bd3 /usr.bin
parent1130e72d7d25306dba63fef7c000b2c78e65b76c (diff)
snprintf() cleanup; OK niallo@.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/import.c15
-rw-r--r--usr.bin/cvs/remove.c17
-rw-r--r--usr.bin/cvs/resp.c73
-rw-r--r--usr.bin/cvs/root.c7
-rw-r--r--usr.bin/cvs/status.c32
5 files changed, 65 insertions, 79 deletions
diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c
index 6b7997d4832..0f2804f355c 100644
--- a/usr.bin/cvs/import.c
+++ b/usr.bin/cvs/import.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: import.c,v 1.35 2006/01/02 08:11:56 xsa Exp $ */
+/* $OpenBSD: import.c,v 1.36 2006/01/25 08:15:05 xsa Exp $ */
/*
* Copyright (c) 2004 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -224,7 +224,6 @@ static int
cvs_import_local(CVSFILE *cf, void *arg)
{
size_t len;
- int l;
time_t stamp;
char *fcont;
char fpath[MAXPATHLEN], rpath[MAXPATHLEN], repo[MAXPATHLEN];
@@ -280,13 +279,11 @@ cvs_import_local(CVSFILE *cf, void *arg)
} else
stamp = -1;
- l = snprintf(rpath, sizeof(rpath), "%s/%s%s",
- repo, fpath, RCS_FILE_EXT);
- if (l == -1 || l >= (int)sizeof(rpath)) {
- errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", rpath);
- return (CVS_EX_DATA);
- }
+ if (strlcpy(rpath, repo, sizeof(rpath)) >= sizeof(rpath) ||
+ strlcat(rpath, "/", sizeof(rpath)) >= sizeof(rpath) ||
+ strlcat(rpath, fpath, sizeof(rpath)) >= sizeof(rpath) ||
+ strlcat(rpath, RCS_FILE_EXT, sizeof(rpath)) >= sizeof(rpath))
+ fatal("cvs_import_local: path truncation");
cvs_printf("N %s\n", fpath);
diff --git a/usr.bin/cvs/remove.c b/usr.bin/cvs/remove.c
index 7f5e2474cc2..b9722ce8cda 100644
--- a/usr.bin/cvs/remove.c
+++ b/usr.bin/cvs/remove.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: remove.c,v 1.40 2006/01/02 08:11:56 xsa Exp $ */
+/* $OpenBSD: remove.c,v 1.41 2006/01/25 08:15:05 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2004, 2005 Xavier Santolaria <xsa@openbsd.org>
@@ -128,7 +128,7 @@ cvs_remove_remote(CVSFILE *cf, void *arg)
static int
cvs_remove_local(CVSFILE *cf, void *arg)
{
- int existing, l, removed;
+ int existing, removed;
char buf[MAXPATHLEN], fpath[MAXPATHLEN];
CVSENTRIES *entf;
struct cvs_ent *ent;
@@ -163,13 +163,12 @@ cvs_remove_local(CVSFILE *cf, void *arg)
if (cvs_ent_remove(entf, cf->cf_name, 0) == -1)
return (CVS_EX_FILE);
- l = snprintf(buf, sizeof(buf), "%s/%s%s",
- CVS_PATH_CVSDIR, cf->cf_name, CVS_DESCR_FILE_EXT);
- if (l == -1 || l >= (int)sizeof(buf)) {
- errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", buf);
- return (CVS_EX_DATA);
- }
+ if (strlcpy(buf, CVS_PATH_CVSDIR, sizeof(buf)) >= sizeof(buf) ||
+ strlcat(buf, "/", sizeof(buf)) >= sizeof(buf) ||
+ strlcat(buf, cf->cf_name, sizeof(buf)) >= sizeof(buf) ||
+ strlcat(buf, CVS_DESCR_FILE_EXT,
+ sizeof(buf)) >= sizeof(buf))
+ fatal("cvs_remove_local: path truncation");
if (cvs_unlink(buf) == -1)
return (CVS_EX_FILE);
diff --git a/usr.bin/cvs/resp.c b/usr.bin/cvs/resp.c
index da56b5f7f2c..7df59648e71 100644
--- a/usr.bin/cvs/resp.c
+++ b/usr.bin/cvs/resp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resp.c,v 1.68 2006/01/02 08:11:56 xsa Exp $ */
+/* $OpenBSD: resp.c,v 1.69 2006/01/25 08:15:05 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -320,7 +320,7 @@ cvs_resp_error(struct cvsroot *root, int type, char *line)
static int
cvs_resp_statdir(struct cvsroot *root, int type, char *line)
{
- int fd, len;
+ int fd;
char rpath[MAXPATHLEN], statpath[MAXPATHLEN];
/* remote directory line */
@@ -333,14 +333,12 @@ cvs_resp_statdir(struct cvsroot *root, int type, char *line)
*/
if (cvs_resp_createdir(line) < 0)
return (-1);
-
- len = snprintf(statpath, sizeof(statpath), "%s/%s", line,
- CVS_PATH_STATICENTRIES);
- if (len == -1 || len >= (int)sizeof(statpath)) {
- cvs_log(LP_ERR,
- "path overflow for Entries.static specification");
+ if (strlcpy(statpath, line, sizeof(statpath)) >= sizeof(statpath) ||
+ strlcat(statpath, "/", sizeof(statpath)) >= sizeof(statpath) ||
+ strlcat(statpath, CVS_PATH_STATICENTRIES,
+ sizeof(statpath)) >= sizeof(statpath))
+ cvs_log(LP_ERR, "Entries.static path truncation");
return (-1);
- }
if (cvs_noexec == 0) {
if ((type == CVS_RESP_CLRSTATDIR) &&
@@ -552,7 +550,6 @@ cvs_resp_cksum(struct cvsroot *root, int type, char *line)
static int
cvs_resp_copyfile(struct cvsroot *root, int type, char *line)
{
- int len;
char path[MAXPATHLEN], newpath[MAXPATHLEN];
char newname[MAXNAMLEN], *file;
@@ -563,16 +560,16 @@ cvs_resp_copyfile(struct cvsroot *root, int type, char *line)
if ((file = basename(path)) == NULL)
fatal("no base file name in Copy-file path");
- len = snprintf(path, sizeof(path), "%s%s", line, file);
- if (len == -1 || len >= (int)sizeof(path))
+ if (strlcpy(path, line, sizeof(path)) >= sizeof(path) ||
+ strlcat(path, file, sizeof(path)) >= sizeof(path))
fatal("source path overflow in Copy-file response");
- len = snprintf(newpath, sizeof(newpath), "%s%s", line, newname);
- if (len == -1 || len >= (int)sizeof(path))
+ if (strlcpy(newpath, line, sizeof(newpath)) >= sizeof(newpath) ||
+ strlcat(newpath, newname, sizeof(newpath)) >= sizeof(newpath))
fatal("destination path overflow in Copy-file response");
if (rename(path, newpath) == -1) {
- fatal("failed to rename %s to %s: %s",
+ fatal("cvs_resp_copyfile: rename: `%s'->`%s': %s",
path, newpath, strerror(errno));
}
@@ -611,6 +608,8 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
struct cvs_ent *ent;
struct timeval tv[2];
+ ret = 0;
+
STRIP_SLASH(line);
/* read the remote path of the file */
@@ -622,12 +621,11 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
if ((ent = cvs_ent_parse(path)) == NULL)
return (-1);
- ret = snprintf(path, sizeof(path), "%s/%s", line, ent->ce_name);
- if (ret == -1 || ret >= (int)sizeof(path))
+ if (strlcpy(path, line, sizeof(path)) >= sizeof(path) ||
+ strlcat(path, "/", sizeof(path)) >= sizeof(path) ||
+ strlcat(path, ent->ce_name, sizeof(path)) >= sizeof(path))
fatal("Entries path overflow in response");
- ret = 0;
-
/*
* Please be sure the directory does exist.
*/
@@ -698,15 +696,16 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
static int
cvs_resp_removed(struct cvsroot *root, int type, char *line)
{
- int l;
char buf[MAXPATHLEN], base[MAXPATHLEN];
char fpath[MAXPATHLEN], *file;
cvs_getln(root, buf, sizeof(buf));
cvs_splitpath(buf, base, sizeof(base), &file);
- l = snprintf(fpath, sizeof(fpath), "%s/%s", line, file);
- if (l == -1 || l >= (int)sizeof(fpath))
+
+ if (strlcpy(fpath, line, sizeof(fpath)) >= sizeof(fpath) ||
+ strlcat(fpath, "/", sizeof(fpath)) >= sizeof(fpath) ||
+ strlcat(fpath, file, sizeof(fpath)) >= sizeof(fpath))
fatal("cvs_resp_removed: overflow in path");
if (resp_check_dir(root, line) < 0)
@@ -755,7 +754,6 @@ cvs_resp_modxpand(struct cvsroot *root, int type, char *line)
static int
cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
{
- int len;
char file[MAXPATHLEN];
char buf[CVS_ENT_MAXLINELEN], cksum_buf[CVS_CKSUM_LEN];
char *fname, *orig, *patch;
@@ -770,9 +768,10 @@ cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
fname = strrchr(buf, '/');
if (fname == NULL)
fname = buf;
- len = snprintf(file, sizeof(file), "%s%s", line, fname);
- if (len == -1 || len >= (int)sizeof(file))
- fatal("path overflow in Rcs-diff response");
+
+ if (strlcpy(file, line, sizeof(file)) >= sizeof(file) ||
+ strlcat(file, fname, sizeof(file)) >= sizeof(file))
+ fatal("cvs_resp_rcsdiff: path truncation");
/* get updated entry fields */
cvs_getln(root, buf, sizeof(buf));
@@ -846,29 +845,29 @@ cvs_resp_template(struct cvsroot *root, int type, char *line)
static int
resp_check_dir(struct cvsroot *root, const char *dir)
{
- int l;
- size_t len;
char cvspath[MAXPATHLEN], repo[MAXPATHLEN];
struct stat st;
/*
* Make sure the CVS directory exists.
*/
- l = snprintf(cvspath, sizeof(cvspath), "%s/%s", dir, CVS_PATH_CVSDIR);
- if (l == -1 || l >= (int)sizeof(cvspath))
+ if (strlcpy(cvspath, dir, sizeof(cvspath)) >= sizeof(cvspath) ||
+ strlcat(cvspath, "/", sizeof(cvspath)) >= sizeof(cvspath) ||
+ strlcat(cvspath, CVS_PATH_CVSDIR,
+ sizeof(cvspath)) >= sizeof(cvspath))
fatal("resp_check_dir: path overflow");
if (stat(cvspath, &st) == -1) {
if (errno != ENOENT)
return (-1);
if (cvs_repo_base != NULL) {
- l = snprintf(repo, sizeof(repo), "%s/%s", cvs_repo_base,
- dir);
- if (l == -1 || l >= (int)sizeof(repo))
+ if (strlcpy(repo, cvs_repo_base,
+ sizeof(repo)) >= sizeof(repo) ||
+ strlcat(repo, "/", sizeof(repo)) >= sizeof(repo) ||
+ strlcat(repo, dir, sizeof(repo)) >= sizeof(repo))
fatal("resp_check_dir: path overflow");
} else {
- len = strlcpy(repo, dir, sizeof(repo));
- if (len >= sizeof(repo))
+ if (strlcpy(repo, dir, sizeof(repo)) >= sizeof(repo))
fatal("resp_check_dir: path truncation");
}
@@ -883,8 +882,8 @@ resp_check_dir(struct cvsroot *root, const char *dir)
if (cvs_resp_lastent == NULL)
return (-1);
- len = strlcpy(cvs_resp_lastdir, dir, sizeof(cvs_resp_lastdir));
- if (len >= sizeof(cvs_resp_lastdir))
+ if (strlcpy(cvs_resp_lastdir, dir,
+ sizeof(cvs_resp_lastdir)) >= sizeof(cvs_resp_lastdir))
fatal("resp_check_dir: path truncation");
} else {
/* make sure the old one is still open */
diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c
index cc0d04a1583..81f8a879c07 100644
--- a/usr.bin/cvs/root.c
+++ b/usr.bin/cvs/root.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: root.c,v 1.28 2006/01/02 08:11:56 xsa Exp $ */
+/* $OpenBSD: root.c,v 1.29 2006/01/25 08:15:05 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -238,7 +238,10 @@ cvsroot_get(const char *dir)
return cvsroot_parse(cvs_rootstr);
l = snprintf(rootpath, sizeof(rootpath), "%s/" CVS_PATH_ROOTSPEC, dir);
- if (l == -1 || l >= (int)sizeof(rootpath)) {
+ if (strlcpy(rootpath, dir, sizeof(rootpath)) >= sizeof(rootpath) ||
+ strlcat(rootpath, "/", sizeof(rootpath)) >= sizeof(rootpath) ||
+ strlcat(rootpath, CVS_PATH_ROOTSPEC,
+ sizeof(rootpath)) >= sizeof(rootpath)) {
errno = ENAMETOOLONG;
fatal("cvsroot_get: %s: %s", rootpath, strerror(errno));
}
diff --git a/usr.bin/cvs/status.c b/usr.bin/cvs/status.c
index ce84cebab52..2e8a07af83f 100644
--- a/usr.bin/cvs/status.c
+++ b/usr.bin/cvs/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.51 2006/01/02 08:11:56 xsa Exp $ */
+/* $OpenBSD: status.c,v 1.52 2006/01/25 08:15:05 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
@@ -154,7 +154,6 @@ cvs_status_remote(CVSFILE *cfp, void *arg)
static int
cvs_status_local(CVSFILE *cf, void *arg)
{
- int len;
size_t n;
char buf[MAXNAMLEN], fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
char numbuf[64], timebuf[32];
@@ -191,13 +190,13 @@ cvs_status_local(CVSFILE *cf, void *arg)
buf, cvs_statstr[cf->cf_cvstat]);
if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- len = snprintf(buf, sizeof(buf), "No entry for %s",
- cf->cf_name);
+ strlcpy(buf, "No entry for ", sizeof(buf));
+ strlcat(buf, cf->cf_name, sizeof(buf));
} else if (cf->cf_cvstat == CVS_FST_ADDED) {
- len = snprintf(buf, sizeof(buf), "New file!");
+ strlcpy(buf, "New file!", sizeof(buf));
} else {
rcsnum_tostr(cf->cf_lrev, numbuf, sizeof(numbuf));
- len = snprintf(buf, sizeof(buf), "%s", numbuf);
+ strlcpy(buf, numbuf, sizeof(buf));
/* Display etime in local mode only. */
if (cvs_cmdop != CVS_OP_SERVER) {
@@ -212,27 +211,16 @@ cvs_status_local(CVSFILE *cf, void *arg)
}
}
- if (len == -1 || len >= (int)sizeof(buf)) {
- if (rf != NULL)
- rcs_close(rf);
- return (CVS_EX_DATA);
- }
-
cvs_printf(" Working revision:\t%s\n", buf);
if (cf->cf_cvstat == CVS_FST_UNKNOWN ||
cf->cf_cvstat == CVS_FST_ADDED) {
- len = snprintf(buf, sizeof(buf), "No revision control file");
+ strlcpy(buf, "No revision control file", sizeof(buf));
} else {
- len = snprintf(buf, sizeof(buf), "%s\t%s",
- rcsnum_tostr(rf->rf_head, numbuf, sizeof(numbuf)),
- rcspath);
- }
-
- if (len == -1 || len >= (int)sizeof(buf)) {
- if (rf != NULL)
- rcs_close(rf);
- return (CVS_EX_DATA);
+ strlcpy(buf, rcsnum_tostr(rf->rf_head, numbuf, sizeof(numbuf)),
+ sizeof(buf));
+ strlcat(buf, "\t", sizeof(buf));
+ strlcat(buf, rcspath, sizeof(buf));
}
cvs_printf(" Repository revision:\t%s\n", buf);