=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/file.c,v retrieving revision 1.60 retrieving revision 1.61 diff -c -r1.60 -r1.61 *** src/usr.bin/cvs/file.c 2005/04/13 20:11:21 1.60 --- src/usr.bin/cvs/file.c 2005/04/16 20:05:05 1.61 *************** *** 1,4 **** ! /* $OpenBSD: file.c,v 1.60 2005/04/13 20:11:21 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: file.c,v 1.61 2005/04/16 20:05:05 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. *************** *** 124,130 **** int cvs_file_init(void) { ! int i; size_t len; char path[MAXPATHLEN], buf[MAXNAMLEN]; FILE *ifp; --- 124,130 ---- int cvs_file_init(void) { ! int i, l; size_t len; char path[MAXPATHLEN], buf[MAXNAMLEN]; FILE *ifp; *************** *** 142,148 **** /* read the cvsignore file in the user's home directory, if any */ pwd = getpwuid(getuid()); if (pwd != NULL) { ! snprintf(path, sizeof(path), "%s/.cvsignore", pwd->pw_dir); ifp = fopen(path, "r"); if (ifp == NULL) { if (errno != ENOENT) --- 142,154 ---- /* read the cvsignore file in the user's home directory, if any */ pwd = getpwuid(getuid()); if (pwd != NULL) { ! l = snprintf(path, sizeof(path), "%s/.cvsignore", pwd->pw_dir); ! if (l == -1 || l >= (int)sizeof(path)) { ! errno = ENAMETOOLONG; ! cvs_log(LP_ERRNO, "%s", path); ! return (-1); ! } ! ifp = fopen(path, "r"); if (ifp == NULL) { if (errno != ENOENT) *************** *** 531,537 **** static int cvs_file_getdir(CVSFILE *cf, int flags) { ! int ret, fd; u_int ndirs; long base; u_char *dp, *ep; --- 537,543 ---- static int cvs_file_getdir(CVSFILE *cf, int flags) { ! int ret, fd, l; u_int ndirs; long base; u_char *dp, *ep; *************** *** 558,564 **** cvs_mkadmin(cf, 0755); /* if the CVS administrative directory exists, load the info */ ! snprintf(pbuf, sizeof(pbuf), "%s/" CVS_PATH_CVSDIR, fpath); if ((stat(pbuf, &st) == 0) && S_ISDIR(st.st_mode)) { if (cvs_readrepo(fpath, pbuf, sizeof(pbuf)) == 0) { cdp->cd_repo = strdup(pbuf); --- 564,576 ---- cvs_mkadmin(cf, 0755); /* if the CVS administrative directory exists, load the info */ ! l = snprintf(pbuf, sizeof(pbuf), "%s/" CVS_PATH_CVSDIR, fpath); ! if (l == -1 || l >= (int)sizeof(pbuf)) { ! errno = ENAMETOOLONG; ! cvs_log(LP_ERRNO, "%s", pbuf); ! return (-1); ! } ! if ((stat(pbuf, &st) == 0) && S_ISDIR(st.st_mode)) { if (cvs_readrepo(fpath, pbuf, sizeof(pbuf)) == 0) { cdp->cd_repo = strdup(pbuf); *************** *** 621,628 **** continue; } ! snprintf(pbuf, sizeof(pbuf), "%s/%s", fpath, ent->d_name); cfp = cvs_file_lget(pbuf, flags, cf); if (cfp == NULL) { (void)close(fd); --- 633,648 ---- continue; } ! l = snprintf(pbuf, sizeof(pbuf), "%s/%s", fpath, ent->d_name); + if (l == -1 || l >= (int)sizeof(pbuf)) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", pbuf); + + (void)close(fd); + return (-1); + } + cfp = cvs_file_lget(pbuf, flags, cf); if (cfp == NULL) { (void)close(fd); *************** *** 645,652 **** * entry in the Entries file but no file on disk */ while ((cvsent = cvs_ent_next(cdp->cd_ent)) != NULL) { ! snprintf(pbuf, sizeof(pbuf), "%s/%s", fpath, cvsent->ce_name); cfp = cvs_file_lget(pbuf, flags, cf); if (cfp != NULL) { if (cfp->cf_type == DT_DIR) { --- 665,680 ---- * entry in the Entries file but no file on disk */ while ((cvsent = cvs_ent_next(cdp->cd_ent)) != NULL) { ! l = snprintf(pbuf, sizeof(pbuf), "%s/%s", fpath, cvsent->ce_name); + if (l == -1 || l >= (int)sizeof(pbuf)) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", pbuf); + + (void)close(fd); + return (-1); + } + cfp = cvs_file_lget(pbuf, flags, cf); if (cfp != NULL) { if (cfp->cf_type == DT_DIR) {