From d3a203f14d22dc0945f371c3694598530f957346 Mon Sep 17 00:00:00 2001 From: Xavier Santolaria Date: Wed, 25 Jan 2006 11:19:52 +0000 Subject: strings cleanup; OK niallo@. --- usr.bin/cvs/add.c | 52 ++++++++++++++++++++++--------------------------- usr.bin/cvs/util.c | 57 +++++++++++++++++++++++++----------------------------- 2 files changed, 49 insertions(+), 60 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c index 75460e4b1bd..9404b12d205 100644 --- a/usr.bin/cvs/add.c +++ b/usr.bin/cvs/add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: add.c,v 1.37 2006/01/02 08:11:56 xsa Exp $ */ +/* $OpenBSD: add.c,v 1.38 2006/01/25 11:19:51 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * Copyright (c) 2005 Xavier Santolaria @@ -215,7 +215,7 @@ cvs_add_local(CVSFILE *cf, void *arg) static int cvs_add_directory(CVSFILE *cf) { - int l, nb; + int nb; char *date, *repo, *tag; char entry[CVS_ENT_MAXLINELEN], fpath[MAXPATHLEN], rcsdir[MAXPATHLEN]; char msg[1024]; @@ -244,13 +244,10 @@ cvs_add_directory(CVSFILE *cf) /* XXX check for /CVS */ - l = snprintf(rcsdir, sizeof(rcsdir), "%s/%s", - root->cr_dir, repo); - if (l == -1 || l >= (int)sizeof(rcsdir)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", rcsdir); - return (CVS_EX_DATA); - } + if (strlcpy(rcsdir, root->cr_dir, sizeof(rcsdir)) >= sizeof(rcsdir) || + strlcat(rcsdir, "/", sizeof(rcsdir)) >= sizeof(rcsdir) || + strlcat(rcsdir, repo, sizeof(rcsdir)) >= sizeof(rcsdir)) + fatal("cvs_add_directory: path truncation"); if ((stat(rcsdir, &st) == 0) && !(S_ISDIR(st.st_mode))) { cvs_log(LP_ERRNO, @@ -286,12 +283,10 @@ cvs_add_directory(CVSFILE *cf) return (CVS_EX_FILE); /* XXX Build the Entries line. */ - l = snprintf(entry, sizeof(entry), "D/%s////", fpath); - if (l == -1 || l >= (int)sizeof(entry)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", entry); - return (CVS_EX_DATA); - } + if (strlcpy(entry, "D/", sizeof(entry)) >= sizeof(entry) || + strlcat(entry, fpath, sizeof(entry)) >= sizeof(entry) || + strlcat(entry, "////", sizeof(entry)) >= sizeof(entry)) + fatal("cvs_add_directory: path truncation"); if ((ent = cvs_ent_parse(entry)) == NULL) { cvs_log(LP_ERR, "failed to parse entry"); @@ -311,7 +306,6 @@ cvs_add_directory(CVSFILE *cf) static int cvs_add_build_entry(CVSFILE *cf) { - int l; char entry[CVS_ENT_MAXLINELEN], path[MAXPATHLEN]; FILE *fp; CVSENTRIES *entf; @@ -323,13 +317,11 @@ cvs_add_build_entry(CVSFILE *cf) return (0); /* Build the path to the ,t file. */ - l = snprintf(path, sizeof(path), "%s/%s%s", - CVS_PATH_CVSDIR, cf->cf_name, CVS_DESCR_FILE_EXT); - if (l == -1 || l >= (int)sizeof(path)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", path); - return (CVS_EX_DATA); - } + if (strlcpy(path, CVS_PATH_CVSDIR, sizeof(path)) >= sizeof(path) || + strlcat(path, "/", sizeof(path)) >= sizeof(path) || + strlcat(path, cf->cf_name, sizeof(path)) >= sizeof(path) || + strlcat(path, CVS_DESCR_FILE_EXT, sizeof(path)) >= sizeof(path)) + fatal("cvs_add_build_entry: path truncation"); fp = fopen(path, "w+"); if (fp == NULL) { @@ -347,13 +339,15 @@ cvs_add_build_entry(CVSFILE *cf) (void)fclose(fp); /* XXX Build the Entries line. */ - l = snprintf(entry, sizeof(entry), "/%s/0/Initial %s/%s/", - cf->cf_name, cf->cf_name, kbuf); - if (l == -1 || l >= (int)sizeof(entry)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", entry); + if (strlcpy(entry, "/", sizeof(entry)) >= sizeof(entry) || + strlcat(entry, cf->cf_name, sizeof(entry)) >= sizeof(entry) || + strlcat(entry, "/0/Initial ", sizeof(entry)) >= sizeof(entry) || + strlcat(entry, cf->cf_name, sizeof(entry)) >= sizeof(entry) || + strlcat(entry, "/", sizeof(entry)) >= sizeof(entry) || + strlcat(entry, kbuf, sizeof(entry)) >= sizeof(entry) || + strlcat(entry, "/", sizeof(entry)) >= sizeof(entry)) { (void)cvs_unlink(path); - return (CVS_EX_DATA); + fatal("cvs_add_build_entry: path truncation"); } if ((ent = cvs_ent_parse(entry)) == NULL) { diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 524fc10c7df..d9d26c87a19 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.67 2006/01/02 08:23:39 xsa Exp $ */ +/* $OpenBSD: util.c,v 1.68 2006/01/25 11:19:51 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -179,8 +179,6 @@ cvs_strtomode(const char *str, mode_t *mode) void cvs_modetostr(mode_t mode, char *buf, size_t len) { - int l; - size_t l1; char tmp[16], *bp; mode_t um, gm, om; @@ -192,44 +190,39 @@ cvs_modetostr(mode_t mode, char *buf, size_t len) *bp = '\0'; if (um) { - l = snprintf(tmp, sizeof(tmp), "u=%s", cvs_modestr[um]); - if (l == -1 || l >= (int)sizeof(tmp)) + if (strlcpy(tmp, "u=", sizeof(tmp)) >= sizeof(tmp) || + strlcat(tmp, cvs_modestr[um], sizeof(tmp)) >= sizeof(tmp)) fatal("cvs_modetostr: overflow for user mode"); - l1 = strlcat(buf, tmp, len); - if (l1 >= len) + if (strlcat(buf, tmp, len) >= len) fatal("cvs_modetostr: string truncation"); } if (gm) { if (um) { - l1 = strlcat(buf, ",", len); - if (l1 >= len) + if (strlcat(buf, ",", len) >= len) fatal("cvs_modetostr: string truncation"); } - l = snprintf(tmp, sizeof(tmp), "g=%s", cvs_modestr[gm]); - if (l == -1 || l >= (int)sizeof(tmp)) + if (strlcpy(tmp, "g=", sizeof(tmp)) >= sizeof(tmp) || + strlcat(tmp, cvs_modestr[gm], sizeof(tmp)) >= sizeof(tmp)) fatal("cvs_modetostr: overflow for group mode"); - l1 = strlcat(buf, tmp, len); - if (l1 >= len) + if (strlcat(buf, tmp, len) >= len) fatal("cvs_modetostr: string truncation"); } if (om) { if (um || gm) { - l1 = strlcat(buf, ",", len); - if (l1 >= len) + if (strlcat(buf, ",", len) >= len) fatal("cvs_modetostr: string truncation"); } - l = snprintf(tmp, sizeof(tmp), "o=%s", cvs_modestr[gm]); - if (l == -1 || l >= (int)sizeof(tmp)) + if (strlcpy(tmp, "o=", sizeof(tmp)) >= sizeof(tmp) || + strlcat(tmp, cvs_modestr[gm], sizeof(tmp)) >= sizeof(tmp)) fatal("cvs_modetostr: overflow for others mode"); - l1 = strlcat(buf, tmp, len); - if (l1 >= len) + if (strlcat(buf, tmp, len) >= len) fatal("cvs_modetostr: string truncation"); } } @@ -636,8 +629,7 @@ done: int cvs_create_dir(const char *path, int create_adm, char *root, char *repo) { - size_t l; - int len, ret; + int ret; char *d, *s; struct stat sb; char rpath[MAXPATHLEN], entry[MAXPATHLEN]; @@ -677,12 +669,10 @@ cvs_create_dir(const char *path, int create_adm, char *root, char *repo) * Create administrative files if requested. */ if (create_adm == 1) { - l = strlcat(rpath, d, sizeof(rpath)); - if (l >= sizeof(rpath)) + if (strlcat(rpath, d, sizeof(rpath)) >= sizeof(rpath)) fatal("cvs_create_dir: path truncation"); - l = strlcat(rpath, "/", sizeof(rpath)); - if (l >= sizeof(rpath)) + if (strlcat(rpath, "/", sizeof(rpath)) >= sizeof(rpath)) fatal("cvs_create_dir: path truncation"); if (cvs_mkadmin(d, root, rpath, NULL, NULL, 0) < 0) { @@ -697,8 +687,11 @@ cvs_create_dir(const char *path, int create_adm, char *root, char *repo) */ entf = cvs_ent_open(".", O_RDWR); if (entf != NULL && strcmp(d, ".")) { - len = snprintf(entry, sizeof(entry), "D/%s////", d); - if (len == -1 || len >= (int)sizeof(entry)) + if (strlcpy(entry, "D/", sizeof(entry)) >= + sizeof(entry) || + strlcat(entry, d, sizeof(entry)) >= sizeof(entry) || + strlcat(entry, "////", sizeof(entry)) >= + sizeof(entry)) fatal("cvs_create_dir: overflow in entry buf"); if ((ent = cvs_ent_parse(entry)) == NULL) { @@ -776,16 +769,18 @@ cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen) char * cvs_rcs_getpath(CVSFILE *file, char *buf, size_t len) { - int l; char *repo; struct cvsroot *root; root = CVS_DIR_ROOT(file); repo = CVS_DIR_REPO(file); - l = snprintf(buf, len, "%s/%s/%s%s", - root->cr_dir, repo, file->cf_name, RCS_FILE_EXT); - if (l == -1 || l >= (int)len) + if (strlcpy(buf, root->cr_dir, len) >= len || + strlcat(buf, "/", len) >= len || + strlcat(buf, repo, len) >= len || + strlcat(buf, "/", len) >= len || + strlcat(buf, file->cf_name, len) >= len || + strlcat(buf, RCS_FILE_EXT, len) >= len) fatal("cvs_rcs_getpath: path truncation"); return (buf); -- cgit v1.2.3