Date: Thu, 12 Jul 2007 23:42:53 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123409 for review Message-ID: <200707122342.l6CNgrjB037508@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123409 Change 123409 by gcooper@optimus-revised_pkgtools on 2007/07/12 23:42:51 -Fixed bug (was incrementing one too many in file read). -Removed old read_plist(..) function. -Swapped around some checks in plist_cmd(..). -Removed some debug statements. Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#6 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#6 (text+ko) ==== @@ -375,9 +375,6 @@ } - else if (!strcmp(cmd, "srcdir")) - return PLIST_SRC; - else if (*cmd == 'm') { if(!strcmp(cmd+1, "ode")) @@ -396,6 +393,8 @@ } + else if (!strcmp(cmd, "srcdir")) + return PLIST_SRC; else if (!strcmp(cmd, "group")) return PLIST_CHGRP; else if (!strcmp(cmd, "pkgdep")) @@ -423,81 +422,76 @@ int cmd; - int i = 0; + unsigned int i = 0; pkg->fmtver_maj = 1; - pkg->fmtver_mnr = 0; + pkg->fmtver_mnr = 2; pkg->origin = NULL; - if(fstat( fileno(fp), &contents_stat )) { + if(fstat( fileno(fp), &contents_stat )) err(-1, "Could not fstat +CONTENTS file"); - } + /* Empty file -- don't attempt to process */ assert(contents_stat.st_size != 0); - plines = (char*) calloc(1, contents_stat.st_size); + plines = (char*) malloc(contents_stat.st_size); - for(i = 0; !feof(fp) && i <= contents_stat.st_size; i++) + for(i = 0; !feof(fp) && i < contents_stat.st_size; i++) *(plines+i) = fgetc(fp); // printf("+CONTENTS DUMP: %s\n", plines); /* Avoid strangely crafted files with zero-length, but non-zero size */ - assert(i != 0); + assert(0 != i); + /* Just in case file doesn't have EOF */ *(plines+i) = '\0'; pline = strtok(plines, "\n"); - if(trim_end_whitespace(pline)) { + if(0 == trim_end_whitespace(pline)) + errx(-1, "Length of first line was 0. This shouldn't happen"); - if(*pline != CMD_CHAR) { - cmd = PLIST_FILE; - } + cp = pline; - else { + if(*pline != CMD_CHAR) + cmd = PLIST_FILE; + else { - int major, minor; + int major, minor; - pline++; + cmd = plist_cmd(pline+1, &cp); - cp = pline; - - cmd = plist_cmd(pline, &cp); - - if (cmd != PLIST_COMMENT) { - errx(-1, "First line of +CONTENTS file was invalid (should be a " + if (cmd != PLIST_COMMENT) { + errx(-1, "First line of +CONTENTS file was invalid (should be a " "package version signature)!\nLine was: %s", pline); - } + } - if (cmd == PLIST_COMMENT && - sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", &major, &minor) == 2) { + if (cmd == PLIST_COMMENT && + sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", &major, &minor) == 2) { - pkg->fmtver_maj = major; - pkg->fmtver_mnr = minor; + pkg->fmtver_maj = major; + pkg->fmtver_mnr = minor; - /* - * If the version is greater than the version major.minor, we - * have a compatibility problem.. - */ - if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) { - warnx("plist format revision (%d.%d) is higher than supported" - "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, - PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); + /* + * If the version is greater than the version major.minor, we + * have a compatibility problem.. + */ + if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) { + warnx("plist format revision (%d.%d) is higher than supported" + "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, + PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); - if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { - cleanup(0); - exit(2); - } - - } + if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { + cleanup(0); + exit(2); + } } } - } else - errx(-1, "Length of first line was 0. This shouldn't happen"); + } add_plist(pkg, cmd, cp); @@ -518,7 +512,9 @@ } else if (*cp == '\0') cp = NULL; - } else + } else if (*cp == '\0') + cp = NULL; + else cmd = PLIST_FILE; add_plist(pkg, cmd, cp); @@ -542,110 +538,6 @@ return len; } -/* Read a packing list from a file */ -void -read_plist_old_np(Package *pkg, FILE *fp) -{ - -#if BUFFER_TRY - -#define MAX_BUFFER_LINES 20 - - char pline[MAX_BUFFER_LINES][FILENAME_MAX]; - - int i = -1; - int j = -1; - -#else - char pline[FILENAME_MAX]; -#endif - - char *cp; - int cmd, len, major, minor; - - pkg->fmtver_maj = 1; - pkg->fmtver_mnr = 0; - pkg->origin = NULL; - -#if BUFFER_TRY - - while (i) { - - for(i = 0; i < MAX_BUFFER_LINES && fgets(pline[i], FILENAME_MAX, fp); i++) ; - - if(!i) - break; - - for(j = 0; j < i; j++) { - - len = strlen(pline[j]); - - while(len && isspace(pline[j][len-1])) - pline[j][--len] = '\0'; - if(!len) - continue; - cp = pline[j]; - -#else - - while (fgets(pline, FILENAME_MAX, fp)) { - len = strlen(pline); - - while (len && isspace(pline[len - 1])) - pline[--len] = '\0'; - if (!len) - continue; - cp = pline; - -#endif - - if (cp[0] != CMD_CHAR) { - cmd = PLIST_FILE; - goto bottom; - } - -#if BUFFER_TRY - cmd = plist_cmd(pline[j] + 1, &cp); -#else - cmd = plist_cmd(pline + 1, &cp); -#endif - - if (cmd == FAIL) { - warnx("%s: unknown command '%s' (package tools out of date?)", - __func__, cp); - goto bottom; - } - if (*cp == '\0') { - cp = NULL; - goto bottom; - } - if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", - &major, &minor) == 2) { - pkg->fmtver_maj = major; - pkg->fmtver_mnr = minor; - if (verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR) <= 0) - goto bottom; - - warnx("plist format revision (%d.%d) is higher than supported" - "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, - PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); - if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { - cleanup(0); - exit(2); - } - } - -bottom: - add_plist(pkg, cmd, cp); -#if BUFFER_TRY - - } -#endif - - } - -} - void write_plist(Package *pkg, FILE *fp) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707122342.l6CNgrjB037508>