RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   22-Jul-2007 04:23:21
  Branch: HEAD                             Handle: 2007072203232100

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               macro.c

  Log:
    - reapply 2.127 with more careful rpmExpand() fix.
    - scale _macro_BUFSIZE as 2 * BUFSIZ (16384) everywhere but rpmExpand()
    - use _macro_BUFSIZ, not compiled in BUFSIZ, to size expansion targets.
    - enable %{dirname:...} macro primitive.

  Summary:
    Revision    Changes     Path
    1.1509      +4  -0      rpm/CHANGES
    2.135       +50 -35     rpm/rpmio/macro.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.1508 -r1.1509 CHANGES
  --- rpm/CHANGES       22 Jul 2007 00:59:07 -0000      1.1508
  +++ rpm/CHANGES       22 Jul 2007 02:23:21 -0000      1.1509
  @@ -1,4 +1,8 @@
   4.5 -> 5.0:
  +    - jbj: reapply 2.127 with more careful rpmExpand() fix.
  +    - jbj: scale _macro_BUFSIZE as 2 * BUFSIZ (16384) everywhere but 
rpmExpand()
  +    - jbj: use _macro_BUFSIZ, not compiled in BUFSIZ, to size expansion 
targets.
  +    - jbj: enable %{dirname:...} macro primitive.
       - nanardon: add the librpmconstant library which provides RPM API 
constants (usually to language bindings)
       - jbj: rescuscitate rpm-perl, include <rpmio.h> explicitly.
       - jbj: perl.prov fiddles (#249135).
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/macro.c
  ============================================================================
  $ cvs diff -u -r2.134 -r2.135 macro.c
  --- rpm/rpmio/macro.c 22 Jul 2007 01:54:12 -0000      2.134
  +++ rpm/rpmio/macro.c 22 Jul 2007 02:23:21 -0000      2.135
  @@ -132,6 +132,9 @@
   
   #define      MACRO_CHUNK_SIZE        16
   
  +/* Size of expansion buffers. */
  +static size_t _macro_BUFSIZ = 2 * BUFSIZ;
  +
   /* forward ref */
   static int expandMacro(MacroBuf mb)
        /[EMAIL PROTECTED] rpmGlobalMacroContext,
  @@ -602,18 +605,19 @@
        /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, fileSystem @*/
        /[EMAIL PROTECTED] mb, rpmGlobalMacroContext, fileSystem @*/
   {
  -    char pcmd[BUFSIZ];
  +    size_t bufn = _macro_BUFSIZ;
  +    char * buf = alloca(bufn);
       FILE *shf;
       int rc;
       int c;
   
  -    strncpy(pcmd, cmd, clen);
  -    pcmd[clen] = '\0';
  -    rc = expandU(mb, pcmd, sizeof(pcmd));
  +    strncpy(buf, cmd, clen);
  +    buf[clen] = '\0';
  +    rc = expandU(mb, buf, bufn);
       if (rc)
        return rc;
   
  -    if ((shf = popen(pcmd, "r")) == NULL)
  +    if ((shf = popen(buf, "r")) == NULL)
        return 1;
       while(mb->nb > 0 && (c = fgetc(shf)) != EOF)
        SAVECHAR(mb, c);
  @@ -642,7 +646,9 @@
        /[EMAIL PROTECTED] mb, rpmGlobalMacroContext @*/
   {
       const char *s = se;
  -    char buf[BUFSIZ], *n = buf, *ne;
  +    size_t bufn = _macro_BUFSIZ;
  +    char *buf = alloca(bufn);
  +    char *n = buf, *ne;
       char *o = NULL, *oe;
       char *b, *be;
       int c;
  @@ -752,7 +758,7 @@
       }
   
   /[EMAIL PROTECTED]@*/
  -    if (expandbody && expandU(mb, b, (&buf[sizeof(buf)] - b))) {
  +    if (expandbody && expandU(mb, b, (&buf[bufn] - b))) {
        rpmError(RPMERR_BADSPEC, _("Macro %%%s failed to expand\n"), n);
        return se;
       }
  @@ -779,7 +785,8 @@
        /[EMAIL PROTECTED] mc, rpmGlobalMacroContext @*/
   {
       const char *s = se;
  -    char buf[BUFSIZ], *n = buf, *ne = n;
  +    char *buf = alloca(_macro_BUFSIZ);
  +    char *n = buf, *ne = n;
       int c;
   
       COPYNAME(ne, s, c);
  @@ -946,7 +953,9 @@
        /[EMAIL PROTECTED] rpmGlobalMacroContext @*/
        /[EMAIL PROTECTED] mb, rpmGlobalMacroContext @*/
   {
  -    char buf[BUFSIZ], *b, *be;
  +    size_t bufn = _macro_BUFSIZ;
  +    char *buf = alloca(bufn);
  +    char *b, *be;
       char aname[16];
       const char *opts, *o;
       int argc = 0;
  @@ -996,7 +1005,7 @@
   
   #ifdef NOTYET
       /* XXX if macros can be passed as args ... */
  -    expandU(mb, buf, sizeof(buf));
  +    expandU(mb, buf, bufn);
   #endif
   
       /* Build argv array */
  @@ -1099,11 +1108,12 @@
        /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, fileSystem @*/
        /[EMAIL PROTECTED] mb, rpmGlobalMacroContext, fileSystem @*/
   {
  -    char buf[BUFSIZ];
  +    size_t bufn = _macro_BUFSIZ + msglen;
  +    char *buf = alloca(bufn);
   
       strncpy(buf, msg, msglen);
       buf[msglen] = '\0';
  -    (void) expandU(mb, buf, sizeof(buf));
  +    (void) expandU(mb, buf, bufn);
       if (waserror)
        rpmError(RPMERR_BADSPEC, "%s\n", buf);
       else
  @@ -1125,18 +1135,22 @@
        /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, fileSystem, 
internalState @*/
        /[EMAIL PROTECTED] mb, rpmGlobalMacroContext, fileSystem, internalState 
@*/
   {
  -    char buf[BUFSIZ], *b = NULL, *be;
  +     size_t bufn = _macro_BUFSIZ + fn + gn;
  +     char * buf = alloca(bufn);
  +     char *b = NULL, *be;
       int c;
   
       buf[0] = '\0';
       if (g != NULL) {
        strncpy(buf, g, gn);
        buf[gn] = '\0';
  -     (void) expandU(mb, buf, sizeof(buf));
  +     (void) expandU(mb, buf, bufn);
       }
   #ifdef       NOTYET
       if (fn > 5 && STREQ("patch", f, 5) && xisdigit(f[5])) {
  -     for ( c = 5 ; c < fn-1 && f[c] == '0' && xisdigit(f[c+1]) ; c++ ) ; /* 
Skip leading zeros */
  +     /* Skip leading zeros */
  +     for (c = 5; c < fn-1 && f[c] == '0' && xisdigit(f[c+1]);)
  +         c++;
        b = buf;
        be = stpncpy( stpcpy(b, "%patch -P "), f+c, fn-c);
        *be = '\0';
  @@ -1147,13 +1161,10 @@
            b = buf;
        else
            b++;
  -#if NOTYET
  -    /* XXX watchout for conflict with %dir */
       } else if (STREQ("dirname", f, fn)) {
        if ((b = strrchr(buf, '/')) != NULL)
            *b = '\0';
        b = buf;
  -#endif
       } else if (STREQ("suffix", f, fn)) {
        if ((b = strrchr(buf, '.')) != NULL)
            b++;
  @@ -1495,6 +1506,7 @@
   
        /* XXX necessary but clunky */
        if (STREQ("basename", f, fn) ||
  +         STREQ("dirname", f, fn) ||
            STREQ("suffix", f, fn) ||
            STREQ("expand", f, fn) ||
            STREQ("verbose", f, fn) ||
  @@ -2012,7 +2024,8 @@
   rpmLoadMacroFile(MacroContext mc, const char * fn)
   {
       FD_t fd = Fopen(fn, "r.fpio");
  -    char buf[BUFSIZ];
  +    size_t bufn = _macro_BUFSIZ;
  +    char *buf = alloca(bufn);
       int rc = -1;
   
       if (fd == NULL || Ferror(fd)) {
  @@ -2022,11 +2035,11 @@
   
       /* XXX Assume new fangled macro expansion */
       /[EMAIL PROTECTED]@*/
  -    max_macro_depth = 16;
  +    max_macro_depth = _MAX_MACRO_DEPTH;
       /[EMAIL PROTECTED]@*/
   
       buf[0] = '\0';
  -    while(rdcl(buf, sizeof(buf), fd) != NULL) {
  +    while(rdcl(buf, bufn, fd) != NULL) {
        char c, *n;
   
        n = buf;
  @@ -2206,14 +2219,14 @@
       const char *s;
       char *t, *te;
       size_t sn, tn;
  -    size_t un = 16 * BUFSIZ;
  +    size_t bufn = 8 * _macro_BUFSIZ;
   
       va_list ap;
   
       if (arg == NULL)
        return xstrdup("");
   
  -    t = xmalloc(strlen(arg) + un + 1);
  +    t = xmalloc(bufn + strlen(arg) + 1);
       *t = '\0';
       te = stpcpy(t, arg);
   
  @@ -2222,7 +2235,7 @@
       while ((s = va_arg(ap, const char *)) != NULL) {
        sn = strlen(s);
        tn = (te - t);
  -     t = xrealloc(t, tn + sn + un + 1);
  +     t = xrealloc(t, tn + sn + bufn + 1);
        te = t + tn;
        te = stpcpy(te, s);
       }
  @@ -2231,8 +2244,8 @@
   
       *te = '\0';
       tn = (te - t);
  -    (void) expandMacros(NULL, NULL, t, tn + un + 1);
  -    t[tn + un] = '\0';
  +    (void) expandMacros(NULL, NULL, t, tn + bufn + 1);
  +    t[tn + bufn] = '\0';
       t = xrealloc(t, strlen(t) + 1);
       
       return t;
  @@ -2360,7 +2373,8 @@
   const char *
   rpmGetPath(const char *path, ...)
   {
  -    char buf[BUFSIZ];
  +    size_t bufn = _macro_BUFSIZ;
  +    char *buf = alloca(bufn);
       const char * s;
       char * t, * te;
       va_list ap;
  @@ -2380,7 +2394,7 @@
       }
       va_end(ap);
   /[EMAIL PROTECTED]@*/
  -    (void) expandMacros(NULL, NULL, buf, sizeof(buf));
  +    (void) expandMacros(NULL, NULL, buf, bufn);
   /[EMAIL PROTECTED]@*/
   
       (void) rpmCleanPath(buf);
  @@ -2510,25 +2524,26 @@
   int
   main(int argc, char *argv[])
   {
  -    char buf[BUFSIZ];
  +    size_t bufn = _macro_BUFSIZ;
  +    char *buf = alloca(bufn);
       FILE *fp;
       int x;
   
       rpmInitMacros(NULL, rpmMacrofiles);
   
       if ((fp = fopen(testfile, "r")) != NULL) {
  -     while(rdcl(buf, sizeof(buf), fp)) {
  -         x = expandMacros(NULL, NULL, buf, sizeof(buf));
  +     while(rdcl(buf, bufn, fp)) {
  +         x = expandMacros(NULL, NULL, buf, bufn);
            fprintf(stderr, "%d->%s\n", x, buf);
  -         memset(buf, 0, sizeof(buf));
  +         memset(buf, 0, bufn);
        }
        fclose(fp);
       }
   
  -    while(rdcl(buf, sizeof(buf), stdin)) {
  -     x = expandMacros(NULL, NULL, buf, sizeof(buf));
  +    while(rdcl(buf, bufn, stdin)) {
  +     x = expandMacros(NULL, NULL, buf, bufn);
        fprintf(stderr, "%d->%s\n <-\n", x, buf);
  -     memset(buf, 0, sizeof(buf));
  +     memset(buf, 0, bufn);
       }
       rpmFreeMacros(NULL);
   
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to