summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-12-30 16:47:37 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-12-30 16:47:37 +0000
commit0b75fabf2a362c8d46c563c1727856429c95590b (patch)
tree7ce59558027d8b470075e06ebe1ad33d091b898f
parentc652e17dc922f98dd69c8e12c38752bf5491bd30 (diff)
more code cleanup, ok niallo@ and xsa@
-rw-r--r--usr.bin/cvs/cvs.h4
-rw-r--r--usr.bin/cvs/proto.c62
-rw-r--r--usr.bin/cvs/proto.h6
-rw-r--r--usr.bin/cvs/req.c5
-rw-r--r--usr.bin/cvs/resp.c116
-rw-r--r--usr.bin/cvs/util.c15
6 files changed, 80 insertions, 128 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 89296c0df67..bd434b0de06 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.94 2005/12/30 02:03:28 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.95 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -430,7 +430,7 @@ struct cvs_lines {
int cvs_readrepo(const char *, char *, size_t);
int cvs_modetostr(mode_t, char *, size_t);
-int cvs_strtomode(const char *, mode_t *);
+void cvs_strtomode(const char *, mode_t *);
int cvs_splitpath(const char *, char *, size_t, char **);
int cvs_mkadmin(const char *, const char *, const char *, char *,
char *, int);
diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c
index ae9e5566820..3cb5b4eea79 100644
--- a/usr.bin/cvs/proto.c
+++ b/usr.bin/cvs/proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.c,v 1.82 2005/12/30 02:03:28 joris Exp $ */
+/* $OpenBSD: proto.c,v 1.83 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -559,23 +559,14 @@ cvs_recvfile(struct cvsroot *root, mode_t *mode)
fbuf = cvs_buf_alloc(sizeof(buf), BUF_AUTOEXT);
- if ((cvs_getln(root, buf, sizeof(buf)) < 0) ||
- (cvs_strtomode(buf, mode) < 0)) {
- cvs_buf_free(fbuf);
- return (NULL);
- }
+ cvs_getln(root, buf, sizeof(buf));
+ cvs_strtomode(buf, mode);
- if (cvs_getln(root, buf, sizeof(buf)) < 0) {
- cvs_buf_free(fbuf);
- return (NULL);
- }
+ cvs_getln(root, buf, sizeof(buf));
fsz = (off_t)strtol(buf, &ep, 10);
- if (*ep != '\0') {
- cvs_log(LP_ERR, "parse error in file size transmission");
- cvs_buf_free(fbuf);
- return (NULL);
- }
+ if (*ep != '\0')
+ fatal("parse error in file size transmission");
cnt = 0;
do {
@@ -583,18 +574,7 @@ cvs_recvfile(struct cvsroot *root, mode_t *mode)
if (len == 0)
break;
ret = cvs_recvraw(root, buf, len);
- if (ret == -1) {
- cvs_buf_free(fbuf);
- return (NULL);
- }
-
- if (cvs_buf_append(fbuf, buf, (size_t)ret) == -1) {
- cvs_log(LP_ERR,
- "failed to append received file data");
- cvs_buf_free(fbuf);
- return (NULL);
- }
-
+ cvs_buf_append(fbuf, buf, (size_t)ret);
cnt += (off_t)ret;
} while (cnt < fsz);
@@ -696,10 +676,8 @@ cvs_getresp(struct cvsroot *root)
*
* Get a line from the remote end and store it in <lbuf>. The terminating
* newline character is stripped from the result.
- * Returns the length in bytes of the line (not including the NUL byte), or
- * -1 on failure.
*/
-int
+void
cvs_getln(struct cvsroot *root, char *lbuf, size_t len)
{
size_t rlen;
@@ -712,8 +690,8 @@ cvs_getln(struct cvsroot *root, char *lbuf, size_t len)
if (fgets(lbuf, (int)len, in) == NULL) {
if (ferror(in)) {
- cvs_log(LP_ERRNO, "failed to read line");
- return (-1);
+ fatal("cvs_getln: error reading server: %s",
+ strerror(errno));
}
if (feof(in))
@@ -726,8 +704,6 @@ cvs_getln(struct cvsroot *root, char *lbuf, size_t len)
rlen = strlen(lbuf);
if ((rlen > 0) && (lbuf[rlen - 1] == '\n'))
lbuf[--rlen] = '\0';
-
- return (rlen);
}
@@ -863,7 +839,7 @@ cvs_sendraw(struct cvsroot *root, const void *src, size_t len)
*
* Receive the first <len> bytes from the buffer <src> to the server.
*/
-ssize_t
+size_t
cvs_recvraw(struct cvsroot *root, void *dst, size_t len)
{
size_t ret;
@@ -875,11 +851,17 @@ cvs_recvraw(struct cvsroot *root, void *dst, size_t len)
in = root->cr_srvout;
ret = fread(dst, sizeof(char), len, in);
- if (ret == 0)
- return (-1);
- if (cvs_server_outlog != NULL)
- fwrite(dst, sizeof(char), len, cvs_server_outlog);
- return (ssize_t)ret;
+ if (ret == 0) {
+ if (ferror(in)) {
+ fatal("cvs_recvraw: error reading from server: %s",
+ strerror(errno));
+ }
+ } else {
+ if (cvs_server_outlog != NULL)
+ fwrite(dst, sizeof(char), len, cvs_server_outlog);
+ }
+
+ return (ret);
}
diff --git a/usr.bin/cvs/proto.h b/usr.bin/cvs/proto.h
index 1df7b7ff2a0..cbbfa98a93a 100644
--- a/usr.bin/cvs/proto.h
+++ b/usr.bin/cvs/proto.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.h,v 1.9 2005/12/30 02:03:28 joris Exp $ */
+/* $OpenBSD: proto.h,v 1.10 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -184,13 +184,13 @@ char* cvs_resp_getvalid(void);
void cvs_sendreq(struct cvsroot *, u_int, const char *);
void cvs_getresp(struct cvsroot *);
int cvs_sendresp(u_int, const char *);
-int cvs_getln(struct cvsroot *, char *, size_t);
+void cvs_getln(struct cvsroot *, char *, size_t);
void cvs_senddir(struct cvsroot *, CVSFILE *);
void cvs_sendarg(struct cvsroot *, const char *, int);
void cvs_sendln(struct cvsroot *, const char *);
void cvs_sendentry(struct cvsroot *, const CVSFILE *);
void cvs_sendraw(struct cvsroot *, const void *, size_t);
-ssize_t cvs_recvraw(struct cvsroot *, void *, size_t);
+size_t cvs_recvraw(struct cvsroot *, void *, size_t);
#endif /* PROTO_H */
diff --git a/usr.bin/cvs/req.c b/usr.bin/cvs/req.c
index ea9237959c3..e1c3e4b41f6 100644
--- a/usr.bin/cvs/req.c
+++ b/usr.bin/cvs/req.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: req.c,v 1.38 2005/12/24 19:07:52 xsa Exp $ */
+/* $OpenBSD: req.c,v 1.39 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -266,8 +266,7 @@ cvs_req_directory(int reqid, char *line)
pwd = (!strcmp(line, "."));
- if (cvs_getln(NULL, rdir, sizeof(rdir)) < 0)
- return (-1);
+ cvs_getln(NULL, rdir, sizeof(rdir));
STRIP_SLASH(rdir);
diff --git a/usr.bin/cvs/resp.c b/usr.bin/cvs/resp.c
index 98aac46d694..a81af510ced 100644
--- a/usr.bin/cvs/resp.c
+++ b/usr.bin/cvs/resp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resp.c,v 1.66 2005/12/29 21:28:26 joris Exp $ */
+/* $OpenBSD: resp.c,v 1.67 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -336,8 +336,7 @@ cvs_resp_statdir(struct cvsroot *root, int type, char *line)
char rpath[MAXPATHLEN], statpath[MAXPATHLEN];
/* remote directory line */
- if (cvs_getln(root, rpath, sizeof(rpath)) < 0)
- return (-1);
+ cvs_getln(root, rpath, sizeof(rpath));
STRIP_SLASH(line);
@@ -387,8 +386,7 @@ cvs_resp_sticky(struct cvsroot *root, int type, char *line)
char buf[MAXPATHLEN];
/* get the remote path */
- if (cvs_getln(root, buf, sizeof(buf)) < 0)
- return (-1);
+ cvs_getln(root, buf, sizeof(buf));
STRIP_SLASH(line);
@@ -501,12 +499,10 @@ cvs_resp_newentry(struct cvsroot *root, int type, char *line)
struct cvs_ent *ent;
/* get the remote path */
- if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0)
- return (-1);
+ cvs_getln(root, entbuf, sizeof(entbuf));
/* get the new Entries line */
- if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0)
- return (-1);
+ cvs_getln(root, entbuf, sizeof(entbuf));
if (resp_check_dir(root, line) < 0)
return (-1);
@@ -569,33 +565,27 @@ static int
cvs_resp_copyfile(struct cvsroot *root, int type, char *line)
{
int len;
- char path[MAXPATHLEN], newpath[MAXPATHLEN], newname[MAXNAMLEN], *file;
+ char path[MAXPATHLEN], newpath[MAXPATHLEN];
+ char newname[MAXNAMLEN], *file;
/* read the remote path of the file to copy and its new name */
- if ((cvs_getln(root, path, sizeof(path)) < 0) ||
- (cvs_getln(root, newname, sizeof(newname)) < 0))
- return (-1);
+ cvs_getln(root, path, sizeof(path));
+ cvs_getln(root, newname, sizeof(newname));
- if ((file = basename(path)) == NULL) {
- cvs_log(LP_ERR, "no base file name in Copy-file path");
- return (-1);
- }
+ 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)) {
- cvs_log(LP_ERR, "source path overflow in Copy-file response");
- return (-1);
- }
+ if (len == -1 || len >= (int)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)) {
- cvs_log(LP_ERR,
- "destination path overflow in Copy-file response");
- return (-1);
- }
+ if (len == -1 || len >= (int)sizeof(path))
+ fatal("destination path overflow in Copy-file response");
if (rename(path, newpath) == -1) {
- cvs_log(LP_ERRNO, "failed to rename %s to %s", path, newpath);
- return (-1);
+ fatal("failed to rename %s to %s: %s",
+ path, newpath, strerror(errno));
}
return (0);
@@ -636,20 +626,18 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
STRIP_SLASH(line);
/* read the remote path of the file */
- if (cvs_getln(root, path, sizeof(path)) < 0)
- return (-1);
+ cvs_getln(root, path, sizeof(path));
/* read the new entry */
- if (cvs_getln(root, path, sizeof(path)) < 0)
- return (-1);
+ cvs_getln(root, path, sizeof(path));
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)) {
- cvs_log(LP_ERR, "Entries path overflow in response");
- return (-1);
- }
+ if (ret == -1 || ret >= (int)sizeof(path))
+ fatal("Entries path overflow in response");
+
ret = 0;
/*
@@ -675,13 +663,9 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
}
}
- if (cvs_ent_add(cvs_resp_lastent, ent) < 0) {
- cvs_ent_free(ent);
- return (-1);
- }
+ cvs_ent_add(cvs_resp_lastent, ent);
- if ((fbuf = cvs_recvfile(root, &fmode)) == NULL)
- return (-1);
+ fbuf = cvs_recvfile(root, &fmode);
cvs_buf_write(fbuf, path, fmode);
cvs_buf_free(fbuf);
@@ -727,18 +711,15 @@ static int
cvs_resp_removed(struct cvsroot *root, int type, char *line)
{
int l;
- char buf[MAXPATHLEN], base[MAXPATHLEN], fpath[MAXPATHLEN], *file;
+ char buf[MAXPATHLEN], base[MAXPATHLEN];
+ char fpath[MAXPATHLEN], *file;
- if (cvs_getln(root, buf, sizeof(buf)) < 0)
- return (-1);
+ 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)) {
- errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", fpath);
- return (-1);
- }
+ if (l == -1 || l >= (int)sizeof(fpath))
+ fatal("cvs_resp_removed: overflow in path");
if (resp_check_dir(root, line) < 0)
return (-1);
@@ -762,10 +743,7 @@ cvs_resp_removed(struct cvsroot *root, int type, char *line)
static int
cvs_resp_mode(struct cvsroot *root, int type, char *line)
{
- if (cvs_strtomode(line, &cvs_lastmode) < 0) {
- cvs_log(LP_ERR, "error handling Mode response");
- return (-1);
- }
+ cvs_strtomode(line, &cvs_lastmode);
return (0);
}
@@ -799,21 +777,17 @@ cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
struct cvs_ent *ent;
/* get remote path and build local path of file to be patched */
- if (cvs_getln(root, buf, sizeof(buf)) < 0)
- return (-1);
+ cvs_getln(root, buf, sizeof(buf));
fname = strrchr(buf, '/');
if (fname == NULL)
fname = buf;
len = snprintf(file, sizeof(file), "%s%s", line, fname);
- if (len == -1 || len >= (int)sizeof(file)) {
- cvs_log(LP_ERR, "path overflow in Rcs-diff response");
- return (-1);
- }
+ if (len == -1 || len >= (int)sizeof(file))
+ fatal("path overflow in Rcs-diff response");
/* get updated entry fields */
- if (cvs_getln(root, buf, sizeof(buf)) < 0)
- return (-1);
+ cvs_getln(root, buf, sizeof(buf));
ent = cvs_ent_parse(buf);
if (ent == NULL)
@@ -872,8 +846,7 @@ cvs_resp_template(struct cvsroot *root, int type, char *line)
BUF *tmpl;
tmpl = cvs_recvfile(root, &mode);
- if (tmpl == NULL)
- return (-1);
+ cvs_buf_free(tmpl);
return (0);
}
@@ -895,7 +868,7 @@ resp_check_dir(struct cvsroot *root, const char *dir)
*/
l = snprintf(cvspath, sizeof(cvspath), "%s/%s", dir, CVS_PATH_CVSDIR);
if (l == -1 || l >= (int)sizeof(cvspath))
- return (-1);
+ fatal("resp_check_dir: path overflow");
if (stat(cvspath, &st) == -1) {
if (errno != ENOENT)
@@ -904,9 +877,11 @@ resp_check_dir(struct cvsroot *root, const char *dir)
l = snprintf(repo, sizeof(repo), "%s/%s", cvs_repo_base,
dir);
if (l == -1 || l >= (int)sizeof(repo))
- return (-1);
+ fatal("resp_check_dir: path overflow");
} else {
- strlcpy(repo, dir, sizeof(repo));
+ len = strlcpy(repo, dir, sizeof(repo));
+ if (len >= sizeof(repo))
+ fatal("resp_check_dir: path truncation");
}
if (cvs_mkadmin(dir, root->cr_str, repo, NULL, NULL, 0) < 0)
@@ -921,11 +896,8 @@ resp_check_dir(struct cvsroot *root, const char *dir)
return (-1);
len = strlcpy(cvs_resp_lastdir, dir, sizeof(cvs_resp_lastdir));
- if (len >= sizeof(cvs_resp_lastdir)) {
- errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", cvs_resp_lastdir);
- return (-1);
- }
+ if (len >= sizeof(cvs_resp_lastdir))
+ fatal("resp_check_dir: path truncation");
} else {
/* make sure the old one is still open */
if (cvs_resp_lastent == NULL) {
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index c912c7cc58d..922f865419e 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.63 2005/12/24 19:07:52 xsa Exp $ */
+/* $OpenBSD: util.c,v 1.64 2005/12/30 16:47:36 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -124,19 +124,20 @@ cvs_readrepo(const char *dir, char *dst, size_t len)
* The CVS protocol specification states that any modes or mode types that are
* not recognized should be silently ignored. This function does not return
* an error in such cases, but will issue warnings.
- * Returns 0 on success, or -1 on failure.
*/
-int
+void
cvs_strtomode(const char *str, mode_t *mode)
{
char type;
+ size_t l;
mode_t m;
char buf[32], ms[4], *sp, *ep;
m = 0;
- if (strlcpy(buf, str, sizeof(buf)) >= sizeof(buf)) {
- return (-1);
- }
+ l = strlcpy(buf, str, sizeof(buf));
+ if (l >= sizeof(buf))
+ fatal("cvs_strtomode: string truncation");
+
sp = buf;
ep = sp;
@@ -174,8 +175,6 @@ cvs_strtomode(const char *str, mode_t *mode)
}
*mode = m;
-
- return (0);
}