=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/util.c,v retrieving revision 1.20 retrieving revision 1.21 diff -c -r1.20 -r1.21 *** src/usr.bin/cvs/util.c 2004/12/22 00:38:26 1.20 --- src/usr.bin/cvs/util.c 2005/04/16 18:07:35 1.21 *************** *** 1,4 **** ! /* $OpenBSD: util.c,v 1.20 2004/12/22 00:38:26 david Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: util.c,v 1.21 2005/04/16 18:07:35 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. *************** *** 94,108 **** int cvs_readrepo(const char *dir, char *dst, size_t len) { size_t dlen; FILE *fp; char repo_path[MAXPATHLEN]; ! snprintf(repo_path, sizeof(repo_path), "%s/CVS/Repository", dir); fp = fopen(repo_path, "r"); ! if (fp == NULL) { return (-1); - } if (fgets(dst, (int)len, fp) == NULL) { if (ferror(fp)) { --- 94,114 ---- int cvs_readrepo(const char *dir, char *dst, size_t len) { + int l; size_t dlen; FILE *fp; char repo_path[MAXPATHLEN]; ! l = snprintf(repo_path, sizeof(repo_path), "%s/CVS/Repository", dir); ! if (l == -1 || l >= (int)sizeof(repo_path)) { ! errno = ENAMETOOLONG; ! cvs_log(LP_ERRNO, "%s", repo_path); ! return (NULL); ! } ! fp = fopen(repo_path, "r"); ! if (fp == NULL) return (-1); if (fgets(dst, (int)len, fp) == NULL) { if (ferror(fp)) { *************** *** 495,500 **** --- 501,507 ---- int cvs_mkadmin(CVSFILE *cdir, mode_t mode) { + int l; char dpath[MAXPATHLEN], path[MAXPATHLEN]; FILE *fp; CVSENTRIES *ef; *************** *** 503,509 **** cvs_file_getpath(cdir, dpath, sizeof(dpath)); ! snprintf(path, sizeof(path), "%s/" CVS_PATH_CVSDIR, dpath); if ((mkdir(path, mode) == -1) && (errno != EEXIST)) { cvs_log(LP_ERRNO, "failed to create directory %s", path); return (-1); --- 510,522 ---- cvs_file_getpath(cdir, dpath, sizeof(dpath)); ! l = snprintf(path, sizeof(path), "%s/" CVS_PATH_CVSDIR, dpath); ! if (l == -1 || l >= (int)sizeof(path)) { ! errno = ENAMETOOLONG; ! cvs_log(LP_ERRNO, "%s", path); ! return (-1); ! } ! if ((mkdir(path, mode) == -1) && (errno != EEXIST)) { cvs_log(LP_ERRNO, "failed to create directory %s", path); return (-1); *************** *** 514,520 **** (void)cvs_ent_close(ef); root = cdir->cf_ddat->cd_root; ! snprintf(path, sizeof(path), "%s/" CVS_PATH_ROOTSPEC, dpath); if ((root != NULL) && (stat(path, &st) != 0) && (errno == ENOENT)) { fp = fopen(path, "w"); if (fp == NULL) { --- 527,539 ---- (void)cvs_ent_close(ef); root = cdir->cf_ddat->cd_root; ! l = snprintf(path, sizeof(path), "%s/" CVS_PATH_ROOTSPEC, dpath); ! if (l == -1 || l >= (int)sizeof(path)) { ! errno = ENAMETOOLONG; ! cvs_log(LP_ERRNO, "%s", path); ! return (-1); ! } ! if ((root != NULL) && (stat(path, &st) != 0) && (errno == ENOENT)) { fp = fopen(path, "w"); if (fp == NULL) { *************** *** 541,546 **** --- 560,571 ---- } snprintf(path, sizeof(path), "%s/" CVS_PATH_REPOSITORY, dpath); + if (l == -1 || l >= (int)sizeof(path)) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", path); + return (-1); + } + if ((stat(path, &st) != 0) && (errno == ENOENT) && (cdir->cf_ddat->cd_repo != NULL)) { fp = fopen(path, "w");