From 10f69d3519037e21b125297ff9a1d2ada4b05689 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 26 Mar 2005 08:09:55 +0000 Subject: fix a variety of things i found at coverity. ok joris@ --- usr.bin/cvs/admin.c | 5 +++-- usr.bin/cvs/file.c | 3 ++- usr.bin/cvs/getlog.c | 5 +++-- usr.bin/cvs/log.c | 4 ++-- usr.bin/cvs/proto.c | 8 +++++--- usr.bin/cvs/rcs.c | 13 +++++++++++-- usr.bin/cvs/status.c | 5 +++-- usr.bin/cvs/tag.c | 5 +++-- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/usr.bin/cvs/admin.c b/usr.bin/cvs/admin.c index 1b2eb522559..5b4d74fa1ff 100644 --- a/usr.bin/cvs/admin.c +++ b/usr.bin/cvs/admin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: admin.c,v 1.5 2005/03/11 16:23:34 joris Exp $ */ +/* $OpenBSD: admin.c,v 1.6 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * Copyright (c) 2005 Joris Vink @@ -380,7 +380,8 @@ cvs_admin_file(CVSFILE *cfp, void *arg) rf = rcs_open(rcspath, RCS_READ); if (rf == NULL) { - cvs_ent_free(entp); + if (entp != NULL) + cvs_ent_free(entp); return (-1); } diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index 5365a8c2776..3262a65171a 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.57 2005/03/24 14:35:18 jfb Exp $ */ +/* $OpenBSD: file.c,v 1.58 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -832,6 +832,7 @@ cvs_file_alloc(const char *path, u_int type) cfp->cf_name = cvs_strdup(basename(path)); if (cfp->cf_name == NULL) { cvs_log(LP_ERR, "failed to copy file name"); + cvs_file_free(cfp); return (NULL); } cfp->cf_type = type; diff --git a/usr.bin/cvs/getlog.c b/usr.bin/cvs/getlog.c index b9800d66720..7242718b2a3 100644 --- a/usr.bin/cvs/getlog.c +++ b/usr.bin/cvs/getlog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getlog.c,v 1.14 2005/02/27 00:22:08 jfb Exp $ */ +/* $OpenBSD: getlog.c,v 1.15 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -195,7 +195,8 @@ cvs_getlog_file(CVSFILE *cf, void *arg) rf = rcs_open(fpath, RCS_READ); if (rf == NULL) { - cvs_ent_free(entp); + if (entp != NULL) + cvs_ent_free(entp); return (-1); } diff --git a/usr.bin/cvs/log.c b/usr.bin/cvs/log.c index db91c8f94a2..10875ef1ac9 100644 --- a/usr.bin/cvs/log.c +++ b/usr.bin/cvs/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.11 2005/02/22 16:22:10 jfb Exp $ */ +/* $OpenBSD: log.c,v 1.12 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -204,7 +204,7 @@ cvs_vlog(u_int level, const char *fmt, va_list vap) char prefix[64], buf[1024], ebuf[32]; FILE *out; - if (level > LP_MAX) + if (level >= LP_MAX) return (-1); /* apply any filters */ diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c index e51336db4d5..f155f69dc7f 100644 --- a/usr.bin/cvs/proto.c +++ b/usr.bin/cvs/proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.c,v 1.43 2005/03/13 19:56:14 joris Exp $ */ +/* $OpenBSD: proto.c,v 1.44 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -461,7 +461,7 @@ cvs_resp_getbyid(int respid) { u_int i; - for (i = 0; i < CVS_NBREQ; i++) + for (i = 0; i < CVS_NBRESP; i++) if (cvs_responses[i].resp_id == (u_int)respid) return &(cvs_responses[i]); @@ -477,7 +477,7 @@ cvs_resp_getbyname(const char *rname) { u_int i; - for (i = 0; i < CVS_NBREQ; i++) + for (i = 0; i < CVS_NBRESP; i++) if (strcmp(cvs_responses[i].resp_str, rname) == 0) return &(cvs_responses[i]); @@ -615,6 +615,7 @@ cvs_recvfile(struct cvsroot *root, mode_t *mode) if ((cvs_getln(root, buf, sizeof(buf)) < 0) || (cvs_strtomode(buf, mode) < 0)) { + cvs_buf_free(fbuf); return (NULL); } @@ -623,6 +624,7 @@ cvs_recvfile(struct cvsroot *root, mode_t *mode) 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); } diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 3310f71266f..315c2b52ab3 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.36 2005/03/13 22:50:34 jfb Exp $ */ +/* $OpenBSD: rcs.c,v 1.37 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -1127,7 +1127,7 @@ rcs_kflag_get(const char *flags) const char* rcs_errstr(int code) { - if ((code < 0) || (code > (int)RCS_NERR)) + if ((code < 0) || (code >= (int)RCS_NERR)) return (NULL); return (rcs_errstrs[code]); } @@ -1486,12 +1486,14 @@ rcs_parse_delta(RCSFILE *rfp) cvs_log(LP_ERR, "missing semi-colon after RCS `%s' key", rk->rk_str); + free(tokstr); rcs_freedelta(rdp); return (-1); } if (tok == RCS_TOK_DATE) { if ((datenum = rcsnum_parse(tokstr)) == NULL) { + free(tokstr); rcs_freedelta(rdp); return (-1); } @@ -1501,7 +1503,10 @@ rcs_parse_delta(RCSFILE *rfp) "fields", (datenum->rn_len > 6) ? "too many" : "missing"); + free(tokstr); rcs_freedelta(rdp); + rcsnum_free(datenum); + return (-1); } rdp->rd_date.tm_year = datenum->rn_id[0]; if (rdp->rd_date.tm_year >= 1900) @@ -1691,6 +1696,7 @@ rcs_parse_symbols(RCSFILE *rfp) symp->rs_num = rcsnum_alloc(); if (symp->rs_num == NULL) { cvs_log(LP_ERRNO, "failed to allocate rcsnum info"); + free(symp->rs_name); free(symp); return (-1); } @@ -1768,6 +1774,7 @@ rcs_parse_locks(RCSFILE *rfp) if (type != RCS_TOK_COLON) { cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); + rcsnum_free(lkp->rl_num); free(lkp); return (-1); } @@ -1776,6 +1783,7 @@ rcs_parse_locks(RCSFILE *rfp) if (type != RCS_TOK_NUM) { cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); + rcsnum_free(lkp->rl_num); free(lkp); return (-1); } @@ -1783,6 +1791,7 @@ rcs_parse_locks(RCSFILE *rfp) if (rcsnum_aton(RCS_TOKSTR(rfp), NULL, lkp->rl_num) < 0) { cvs_log(LP_ERR, "failed to parse RCS NUM `%s'", RCS_TOKSTR(rfp)); + rcsnum_free(lkp->rl_num); free(lkp); return (-1); } diff --git a/usr.bin/cvs/status.c b/usr.bin/cvs/status.c index e197513475a..edb0e62bfba 100644 --- a/usr.bin/cvs/status.c +++ b/usr.bin/cvs/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.8 2005/02/27 00:22:08 jfb Exp $ */ +/* $OpenBSD: status.c,v 1.9 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -196,7 +196,8 @@ cvs_status_file(CVSFILE *cfp, void *arg) rf = rcs_open(rcspath, RCS_READ); if (rf == NULL) { - cvs_ent_free(entp); + if (entp != NULL) + cvs_ent_free(entp); return (-1); } diff --git a/usr.bin/cvs/tag.c b/usr.bin/cvs/tag.c index 42c9a520865..967ecf9f04e 100644 --- a/usr.bin/cvs/tag.c +++ b/usr.bin/cvs/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.5 2005/02/28 20:18:02 joris Exp $ */ +/* $OpenBSD: tag.c,v 1.6 2005/03/26 08:09:54 tedu Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * Copyright (c) 2004 Joris Vink @@ -225,7 +225,8 @@ cvs_tag_file(CVSFILE *cfp, void *arg) rf = rcs_open(rcspath, RCS_READ); if (rf == NULL) { - cvs_ent_free(entp); + if (entp != NULL) + cvs_ent_free(entp); return (-1); } -- cgit v1.2.3