RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: jbj@rpm5.org
Module: rpm Date: 22-Sep-2007 23:12:57
Branch: HEAD Handle: 2007092222125601
Modified files:
rpm CHANGES build.c
rpm/rpmio macro.c
Log:
- jbj: handle more white space in paths.
- jbj: make the rpm hacker's entrance exam buggery harder (#281391).
Summary:
Revision Changes Path
1.1638 +2 -0 rpm/CHANGES
2.109 +69 -95 rpm/build.c
2.145 +7 -5 rpm/rpmio/macro.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.1637 -r1.1638 CHANGES
--- rpm/CHANGES 22 Sep 2007 17:40:54 -0000 1.1637
+++ rpm/CHANGES 22 Sep 2007 21:12:56 -0000 1.1638
@@ -1,4 +1,6 @@
4.5 -> 5.0:
+ - jbj: handle more white space in paths.
+ - jbj: make the rpm hacker's entrance exam buggery harder (#281391).
- jbj: don't punish monkeys who insist on "My Widdle .spec" naming.
- jbj: permit -ta spec file extraction from zip/lzo/lzma compressed balls.
- jbj: add %{?__tar_wildcards} to pass Fedora automated regression tests.
@@ .
patch -p0 <<'@@ .'
Index: rpm/build.c
============================================================================
$ cvs diff -u -r2.108 -r2.109 build.c
--- rpm/build.c 22 Sep 2007 17:40:54 -0000 2.108
+++ rpm/build.c 22 Sep 2007 21:12:56 -0000 2.109
@@ -106,10 +106,13 @@
const char * passPhrase = ba->passPhrase;
const char * cookie = ba->cookie;
int buildAmount = ba->buildAmount;
- const char * specFile;
- const char * specURL;
+ const char * specFile = NULL;
+ const char * specURL = NULL;
int specut;
- char buf[BUFSIZ];
+ const char * s;
+ char * se;
+ size_t nb = strlen(arg) + BUFSIZ;
+ char * buf = alloca(nb);
Spec spec = NULL;
int verify = 1;
int xx;
@@ -119,120 +122,90 @@
rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
#endif
- /*@-compmempass@*/ /* FIX: static zcmds heartburn */
if (ba->buildMode == 't') {
+ static const char * sfpats[] = { "Specfile", "\\*.spec", NULL };
static const char _specfn[] = "%{mkstemp:%{_specdir}/rpm-spec.XXXXXX}";
+ char * tmpSpecFile = (char *) rpmGetPath(_specfn, NULL);
FILE *fp;
- const char * specDir;
- char * tmpSpecFile;
- char * cmd, * s;
- int xx;
+ int bingo = 0;
+ int i;
- specDir = rpmGetPath("%{_specdir}", NULL);
-
- tmpSpecFile = (char *) rpmGetPath(_specfn, NULL);
-
- cmd = rpmExpand("%{uncompress:", arg, "} | %{__tar} -xOvf - %{?__tar_wildcards} ", "Specfile", " 2>&1 > '", tmpSpecFile, "'", NULL);
-
- if ((fp = popen(cmd, "r")) == NULL) {
- rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
- cmd = _free(cmd);
+ for (i = 0; sfpats[i]; i++) {
+ se = rpmExpand("%{uncompress: %{u2p:", arg, "}}",
+ " | %{__tar} -xOvf - %{?__tar_wildcards} ", sfpats[i],
+ " 2>&1 > '", tmpSpecFile, "'", NULL);
+ fp = popen(se, "r");
+ se = _free(se);
+ if (fp== NULL)
+ continue;
+ s = fgets(buf, nb - 1, fp);
+ xx = pclose(fp);
+ if (!s || !*s || strstr(s, ": Not found in archive"))
+ continue;
+ bingo = 1;
+ break;
+ }
+ if (!bingo) {
+ rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"), arg);
+ xx = Unlink(tmpSpecFile);
tmpSpecFile = _free(tmpSpecFile);
- specDir = _free(specDir);
return 1;
}
- s = fgets(buf, sizeof(buf) - 1, fp);
- if (!s || !*s || strstr(s, ": Not found in archive")) {
- /* Try again */
- (void) pclose(fp);
- cmd = _free(cmd);
-
- cmd = rpmExpand("%{uncompress:", arg, "} | %{__tar} -xOvf - %{?__tar_wildcards} ", "\\*.spec", " 2>&1 > '", tmpSpecFile, "'", NULL);
- if (!(fp = popen(cmd, "r"))) {
- rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
- cmd = _free(cmd);
- tmpSpecFile = _free(tmpSpecFile);
- specDir = _free(specDir);
- return 1;
- }
- s = fgets(buf, sizeof(buf) - 1, fp);
- if (!s || !*s || strstr(s, ": Not found in archive")) {
- /* Give up */
- rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
- arg);
- xx = unlink(tmpSpecFile);
- cmd = _free(cmd);
- tmpSpecFile = _free(tmpSpecFile);
- specDir = _free(specDir);
- return 1;
- }
- }
- (void) pclose(fp);
- cmd = _free(cmd);
-
- cmd = s = buf;
- while (*cmd != '\0') {
- if (*cmd == '/') s = cmd + 1;
- cmd++;
- }
- cmd = s;
-
- /* remove trailing \n */
- s = cmd + strlen(cmd) - 1;
- *s = '\0';
-
- specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
- sprintf(s, "%s/%s", specDir, cmd);
- xx = Rename(tmpSpecFile, s);
- specDir = _free(specDir);
-
+ s = se = basename(buf);
+ se += strlen(se);
+ while (--se > s && strchr("\r\n", *se) != NULL)
+ *se = '\0';
+ specURL = rpmGetPath("%{_specdir}/", s, NULL);
+ specut = urlPath(specURL, &specFile);
+ xx = Rename(tmpSpecFile, specFile);
if (xx) {
rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
tmpSpecFile, s);
- xx = Unlink(tmpSpecFile);
- tmpSpecFile = _free(tmpSpecFile);
- return 1;
+ (void) Unlink(tmpSpecFile);
}
tmpSpecFile = _free(tmpSpecFile);
+ if (xx)
+ return 1;
- /* Make the directory which contains the tarball the source
- directory for this run */
-
- if (*arg != '/') {
- if (getcwd(buf, BUFSIZ) == NULL) strcpy(buf, ".");
- strcat(buf, "/");
- strcat(buf, arg);
- } else
- strcpy(buf, arg);
-
- cmd = buf + strlen(buf) - 1;
- while (*cmd != '/') cmd--;
- *cmd = '\0';
-
- addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
+ se = buf; *se = '\0';
+ se = stpcpy(se, "_sourcedir ");
+ (void) urlPath(arg, &s);
+ if (*s != '/') {
+ if (getcwd(se, nb - sizeof("_sourcedir ")) > 0)
+ se += strlen(se);
+ else
+ se = stpcpy(se, ".");
+ } else
+ se = stpcpy(se, dirname(strcpy(se, s)));
+ while (se > buf && se[-1] == '/')
+ *se-- = '0';
+ rpmCleanPath(buf + sizeof("_sourcedir ") - 1);
+ rpmDefineMacro(NULL, buf, RMIL_TARBALL);
} else {
- specURL = arg;
- }
- /*@=compmempass@*/
-
- specut = urlPath(specURL, &specFile);
- if (*specFile != '/') {
- char *s = alloca(BUFSIZ);
- if (getcwd(s, BUFSIZ) == NULL) strcpy(s, ".");
- strcat(s, "/");
- strcat(s, arg);
- specURL = s;
+ specut = urlPath(arg, &s);
+ se = buf; *se = '\0';
+ if (*s != '/') {
+ if (getcwd(se, nb - sizeof("_sourcedir ")) > 0)
+ se += strlen(se);
+ else
+ se = stpcpy(se, ".");
+ } else
+ se = stpcpy(se, s);
+ *se++ = '/';
+ se += strlen(basename(strcpy(se, s)));
+ specURL = rpmGetPath(buf, NULL);
+ specut = urlPath(specURL, &specFile);
}
if (specut != URL_IS_DASH) {
- struct stat st;
- if (Stat(specURL, &st) < 0) {
+ struct stat sb;
+ if (Stat(specURL, &sb) < 0) {
rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
rc = 1;
goto exit;
}
- if (! S_ISREG(st.st_mode)) {
+ if (! S_ISREG(sb.st_mode)) {
rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
specURL);
rc = 1;
@@ -283,6 +256,7 @@
exit:
spec = freeSpec(spec);
+ specURL = _free(specURL);
return rc;
}
/*@=boundswrite@*/
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmio/macro.c
============================================================================
$ cvs diff -u -r2.144 -r2.145 macro.c
--- rpm/rpmio/macro.c 22 Sep 2007 16:06:05 -0000 2.144
+++ rpm/rpmio/macro.c 22 Sep 2007 21:12:57 -0000 2.145
@@ -1184,6 +1184,7 @@
/*@-globs@*/
for (b = buf; (c = *b) && isblank(c);)
b++;
+ /* XXX FIXME: file paths with embedded white space needs rework. */
for (be = b; (c = *be) && !isblank(c);)
be++;
/*@=globs@*/
@@ -1195,19 +1196,19 @@
sprintf(be, "%%__cat %s", b);
break;
case 1: /* COMPRESSED_OTHER */
- sprintf(be, "%%__gzip -dc %s", b);
+ sprintf(be, "%%__gzip -dc '%s'", b);
break;
case 2: /* COMPRESSED_BZIP2 */
- sprintf(be, "%%__bzip2 -dc %s", b);
+ sprintf(be, "%%__bzip2 -dc '%s'", b);
break;
case 3: /* COMPRESSED_ZIP */
- sprintf(be, "%%__unzip -qq %s", b);
+ sprintf(be, "%%__unzip -qq '%s'", b);
break;
case 4: /* COMPRESSED_LZOP */
- sprintf(be, "%%__lzop %s", b);
+ sprintf(be, "%%__lzop '%s'", b);
break;
case 5: /* COMPRESSED_LZMA */
- sprintf(be, "%%__lzma %s", b);
+ sprintf(be, "%%__lzma '%s'", b);
break;
}
b = be;
@@ -1215,6 +1216,7 @@
/*@-globs@*/
for (b = buf; (c = *b) && isblank(c);)
b++;
+ /* XXX FIXME: file paths with embedded white space needs rework. */
for (be = b; (c = *be) && !isblank(c);)
be++;
/*@=globs@*/
@@ .
Received on Sat Sep 22 23:12:57 2007