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

  Server: rpm5.org                         Name:   Pinto Elia
  Root:   /v/rpm/cvs                       Email:  devzero2...@rpm5.org
  Module: rpm                              Date:   20-Dec-2011 17:45:57
  Branch: HEAD                             Handle: 2011122016455601

  Modified files:
    rpm                     CHANGES
    rpm/js                  rpmmpw-js.c
    rpm/python              header-py.c rpmdb-py.c rpmfts-py.c rpmmacro-py.c
                            rpmmodule.c rpmtd-py.c rpmts-py.c spec-py.c
    rpm/rpmio               rpmpython.c

  Log:
    call with safety some python API that
    can segfault if called with a NULL pointer.
    Based of the original patch of David Malcom
    http://lists.rpm.org/pipermail/rpm-maint/2011-December/003139.html
    
    In particular:
    - always check  if PyList_New(0) is not NULL
    - substitute the call to Py_DECREF to Py_XDECREF
    
    Probably more check is needed. Todo++

  Summary:
    Revision    Changes     Path
    1.3686      +4  -0      rpm/CHANGES
    1.23        +1  -1      rpm/js/rpmmpw-js.c
    1.115       +57 -11     rpm/python/header-py.c
    1.29        +1  -1      rpm/python/rpmdb-py.c
    1.25        +4  -4      rpm/python/rpmfts-py.c
    1.8         +3  -3      rpm/python/rpmmacro-py.c
    1.182       +12 -10     rpm/python/rpmmodule.c
    1.4         +3  -0      rpm/python/rpmtd-py.c
    1.112       +20 -13     rpm/python/rpmts-py.c
    1.15        +7  -0      rpm/python/spec-py.c
    2.17        +1  -1      rpm/rpmio/rpmpython.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3685 -r1.3686 CHANGES
  --- rpm/CHANGES       10 Nov 2011 12:45:05 -0000      1.3685
  +++ rpm/CHANGES       20 Dec 2011 16:45:56 -0000      1.3686
  @@ -1,4 +1,8 @@
   HEAD:
  +    - devzero2000: call with safety some python API that
  +      can segfault if called with a NULL pointer. 
  +      Based of the original patch of David Malcom
  +      http://lists.rpm.org/pipermail/rpm-maint/2011-December/003139.html
       - proyvind: add support for filtering of files to find-debuginfo.sh.
       - proyvind: fix find-debuginfo.sh mime-type matching.
       - proyvind: fix different epoch being ignored when comparing two packages
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmmpw-js.c
  ============================================================================
  $ cvs diff -u -r1.22 -r1.23 rpmmpw-js.c
  --- rpm/js/rpmmpw-js.c        3 Jun 2011 16:32:15 -0000       1.22
  +++ rpm/js/rpmmpw-js.c        20 Dec 2011 16:45:56 -0000      1.23
  @@ -1167,7 +1167,7 @@
   
       /* Grab long as big-endian unsigned octets. */
       if (_PyLong_AsByteArray(lo, zb, nzb, is_littleendian, is_signed)) {
  -     Py_DECREF(z);
  +     Py_XDECREF(z);
        return NULL;
       }
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/header-py.c
  ============================================================================
  $ cvs diff -u -r1.114 -r1.115 header-py.c
  --- rpm/python/header-py.c    28 Jan 2011 00:26:33 -0000      1.114
  +++ rpm/python/header-py.c    20 Dec 2011 16:45:56 -0000      1.115
  @@ -170,7 +170,9 @@
       HeaderIterator hi;
   
       list = PyList_New(0);
  -
  +    if (!list) {
  +     return NULL;
  +    }
       for (hi = headerInit(s->h);
        headerNext(hi, he, 0);
        he->p.ptr = _free(he->p.ptr))
  @@ -186,8 +188,14 @@
        case RPM_UINT8_TYPE:
        case RPM_STRING_ARRAY_TYPE:
        case RPM_STRING_TYPE:
  -         PyList_Append(list, o=PyInt_FromLong(he->tag));
  -         Py_DECREF(o);
  +            o=PyInt_FromLong(he->tag);
  +            if (!o) {
  +                headerFreeIterator(hi);
  +                Py_XDECREF(list);
  +                return NULL;
  +            }
  +         PyList_Append(list, o);
  +         Py_XDECREF(o);
            break;
        }
       }
  @@ -474,10 +482,17 @@
       case RPM_UINT8_TYPE:
        if (he->c != 1 || forceArray) {
            metao = PyList_New(0);
  +            if (!metao) {
  +             return NULL;
  +            }
            for (i = 0; i < he->c; i++) {
                o = PyInt_FromLong(he->p.ui8p[i]);
  +                if (!o) {
  +                   Py_XDECREF(metao);
  +                   return NULL;
  +                }
                PyList_Append(metao, o);
  -             Py_DECREF(o);
  +             Py_XDECREF(o);
            }
            o = metao;
        } else {
  @@ -488,10 +503,17 @@
       case RPM_UINT16_TYPE:
        if (he->c != 1 || forceArray) {
            metao = PyList_New(0);
  +            if (!metao) {
  +              return NULL;
  +         }
            for (i = 0; i < he->c; i++) {
                o = PyInt_FromLong(he->p.ui16p[i]);
  +                if (!o) {
  +                   Py_XDECREF(metao);
  +                   return NULL;
  +                }
                PyList_Append(metao, o);
  -             Py_DECREF(o);
  +             Py_XDECREF(o);
            }
            o = metao;
        } else {
  @@ -502,10 +524,17 @@
       case RPM_UINT32_TYPE:
        if (he->c != 1 || forceArray) {
            metao = PyList_New(0);
  +            if (!metao) {
  +                     return NULL;
  +            }
            for (i = 0; i < he->c; i++) {
                o = PyInt_FromLong(he->p.ui32p[i]);
  +                if (!o) {
  +                   Py_XDECREF(metao);
  +                   return NULL;
  +                }
                PyList_Append(metao, o);
  -             Py_DECREF(o);
  +             Py_XDECREF(o);
            }
            o = metao;
        } else {
  @@ -516,10 +545,17 @@
       case RPM_UINT64_TYPE:
        if (he->c != 1 || forceArray) {
            metao = PyList_New(0);
  +            if (!metao) {
  +                     return NULL;
  +            }
            for (i = 0; i < he->c; i++) {
                o = PyInt_FromLong(he->p.ui64p[i]);
  +                if (!o) {
  +                   Py_XDECREF(metao);
  +                   return NULL;
  +                }
                PyList_Append(metao, o);
  -             Py_DECREF(o);
  +             Py_XDECREF(o);
            }
            o = metao;
        } else {
  @@ -529,10 +565,17 @@
   
       case RPM_STRING_ARRAY_TYPE:
        metao = PyList_New(0);
  +        if (!metao) {
  +                return NULL;
  +        }
        for (i = 0; i < he->c; i++) {
            o = PyString_FromString(he->p.argv[i]);
  +            if (!o) {
  +                  Py_XDECREF(metao);
  +                  return NULL;
  +            }
            PyList_Append(metao, o);
  -         Py_DECREF(o);
  +         Py_XDECREF(o);
        }
        o = metao;
        break;
  @@ -695,6 +738,9 @@
       }
   
       list = PyList_New(0);
  +    if (!list) {
  +     return NULL;
  +    }
       Py_BEGIN_ALLOW_THREADS
       {   const char item[] = "Header";
        const char * msg = NULL;
  @@ -712,11 +758,11 @@
       while (h) {
        hdr = hdr_Wrap(h);
        if (PyList_Append(list, (PyObject *) hdr)) {
  -         Py_DECREF(list);
  -         Py_DECREF(hdr);
  +         Py_XDECREF(list);
  +         Py_XDECREF(hdr);
            return NULL;
        }
  -     Py_DECREF(hdr);
  +     Py_XDECREF(hdr);
   
        (void)headerFree(h);    /* XXX ref held by hdr */
        h = NULL;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmdb-py.c
  ============================================================================
  $ cvs diff -u -r1.28 -r1.29 rpmdb-py.c
  --- rpm/python/rpmdb-py.c     21 Mar 2010 00:31:09 -0000      1.28
  +++ rpm/python/rpmdb-py.c     20 Dec 2011 16:45:56 -0000      1.29
  @@ -312,7 +312,7 @@
        char * errstr = NULL;
        int errsize;
   
  -     Py_DECREF(o);
  +     Py_XDECREF(o);
        /* PyErr_SetString should take varargs... */
        errsize = strlen(errmsg) + *root == '\0' ? 15 /* "/var/lib/rpm" */ : 
strlen(root);
        errstr = alloca(errsize);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmfts-py.c
  ============================================================================
  $ cvs diff -u -r1.24 -r1.25 rpmfts-py.c
  --- rpm/python/rpmfts-py.c    17 Dec 2008 23:39:30 -0000      1.24
  +++ rpm/python/rpmfts-py.c    20 Dec 2011 16:45:56 -0000      1.25
  @@ -389,11 +389,11 @@
       PyObject_GC_UnTrack((PyObject *)s);
       if (s->md_dict != NULL) {
        _PyModule_Clear((PyObject *)s);
  -     Py_DECREF(s->md_dict);
  +     Py_XDECREF(s->md_dict);
       }
       if (s->callbacks != NULL) {
        _PyModule_Clear((PyObject *)s);
  -     Py_DECREF(s->callbacks);
  +     Py_XDECREF(s->callbacks);
       }
       _PyObject_GC_Del((PyObject *)s);
   }
  @@ -451,7 +451,7 @@
        goto fail;
   
   #define      CONSTANT(_v) \
  -    PyDict_SetItemString(s->md_dict, #_v, o=PyInt_FromLong(_v)); Py_DECREF(o)
  +    PyDict_SetItemString(s->md_dict, #_v, o=PyInt_FromLong(_v)); 
Py_XDECREF(o)
   
       CONSTANT(FTS_ROOTPARENTLEVEL);
       CONSTANT(FTS_ROOTLEVEL);
  @@ -502,7 +502,7 @@
   
    fail:
       Py_XDECREF(n);
  -    Py_DECREF(s);
  +    Py_XDECREF(s);
       return NULL;
   }
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmmacro-py.c
  ============================================================================
  $ cvs diff -u -r1.7 -r1.8 rpmmacro-py.c
  --- rpm/python/rpmmacro-py.c  31 Jul 2008 00:21:42 -0000      1.7
  +++ rpm/python/rpmmacro-py.c  20 Dec 2011 16:45:56 -0000      1.8
  @@ -141,11 +141,11 @@
   
        ndo = PyDict_New();
        if (ndo == NULL) {
  -         Py_DECREF(no);
  +         Py_XDECREF(no);
            break;
        }
        PyDict_SetItem(mdict, no, ndo);
  -     Py_DECREF(ndo);
  +     Py_XDECREF(ndo);
   
        if (o) {
            if ((vo = PyString_FromString(o)) != NULL)
  @@ -165,7 +165,7 @@
   
        if (failed)
            PyDict_DelItem(mdict, no);
  -     Py_DECREF(no);
  +     Py_XDECREF(no);
       }
   
      Py_XDECREF(oo);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmmodule.c
  ============================================================================
  $ cvs diff -u -r1.181 -r1.182 rpmmodule.c
  --- rpm/python/rpmmodule.c    27 Jan 2011 18:24:41 -0000      1.181
  +++ rpm/python/rpmmodule.c    20 Dec 2011 16:45:56 -0000      1.182
  @@ -109,7 +109,9 @@
   
       llen = PyList_Size(check);
       caught = PyList_New(0);
  -
  +    if (!caught) {
  +     return NULL;
  +    }
       /* block signals while checking for them */
       (void) sigfillset(&newMask);
       (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
  @@ -304,8 +306,8 @@
        pyval = PyInt_FromLong(tagval);
        pyname = PyString_FromString(shortname);
        PyDict_SetItem(dict, pyval, pyname);
  -     Py_DECREF(pyval);
  -     Py_DECREF(pyname);
  +     Py_XDECREF(pyval);
  +     Py_XDECREF(pyname);
       }
       PyModule_AddObject(module, "tagnames", dict);
       rpmtdFreeData(names);
  @@ -320,9 +322,9 @@
       PyObject * to;
       for (t = rpmTagTable; t && t->name; t++) {
        PyDict_SetItemString(d, (char *) t->name, to=PyInt_FromLong(t->val));
  -     Py_DECREF(to);
  +     Py_XDECREF(to);
           PyDict_SetItem(dict, to, o=PyString_FromString(t->name + 7));
  -     Py_DECREF(o);
  +     Py_XDECREF(o);
       }
    }
   
  @@ -336,14 +338,14 @@
        if (ext->name == NULL || ext->type != HEADER_EXT_TAG)
            continue;
        PyDict_SetItemString(d, (char *) ext->name, 
to=PyCObject_FromVoidPtr((void *)ext, NULL));
  -     Py_DECREF(to);
  +     Py_XDECREF(to);
           PyDict_SetItem(dict, to, o=PyString_FromString(ext->name + 7));
  -     Py_DECREF(o);
  +     Py_XDECREF(o);
       }
    }
   
       PyDict_SetItemString(d, "tagnames", dict);
  -    Py_DECREF(dict);
  +    Py_XDECREF(dict);
   
   #endif
   }
  @@ -397,7 +399,7 @@
   #ifdef       HACK
       pyrpmError = PyString_FromString("_rpm.error");
       PyDict_SetItemString(d, "error", pyrpmError);
  -    Py_DECREF(pyrpmError);
  +    Py_XDECREF(pyrpmError);
   #else
       pyrpmError = PyErr_NewException("_rpm.error", NULL, NULL);
       if (pyrpmError != NULL)
  @@ -463,7 +465,7 @@
   
   #define REGISTER_ENUM(val) \
       PyDict_SetItemString(d, #val, o=PyInt_FromLong( val )); \
  -    Py_DECREF(o);
  +    Py_XDECREF(o);
   
       REGISTER_ENUM(RPMFILE_STATE_NORMAL);
       REGISTER_ENUM(RPMFILE_STATE_REPLACED);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmtd-py.c
  ============================================================================
  $ cvs diff -u -r1.3 -r1.4 rpmtd-py.c
  --- rpm/python/rpmtd-py.c     10 Sep 2008 12:28:38 -0000      1.3
  +++ rpm/python/rpmtd-py.c     20 Dec 2011 16:45:56 -0000      1.4
  @@ -105,6 +105,9 @@
       
       if (array) {
        res = PyList_New(0);
  +        if (!res) {
  +            return NULL;
  +        }
        while (rpmtdNext(td) >= 0) {
            PyList_Append(res, rpmtd_ItemAsPyobj(td));
        }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmts-py.c
  ============================================================================
  $ cvs diff -u -r1.111 -r1.112 rpmts-py.c
  --- rpm/python/rpmts-py.c     11 Oct 2010 18:39:36 -0000      1.111
  +++ rpm/python/rpmts-py.c     20 Dec 2011 16:45:56 -0000      1.112
  @@ -215,9 +215,9 @@
       cbInfo->dso = rpmds_Wrap(ds);    /* XXX perhaps persistent? */
       args = Py_BuildValue("(OO)", cbInfo->tso, cbInfo->dso);
       result = PyEval_CallObject(cbInfo->cb, args);
  -    Py_DECREF(cbInfo->dso);
  +    Py_XDECREF(cbInfo->dso);
       cbInfo->dso = NULL;
  -    Py_DECREF(args);
  +    Py_XDECREF(args);
   
       if (!result) {
        rpmts_Die(cbInfo->cb);
  @@ -225,7 +225,7 @@
       } else {
        if (PyInt_Check(result))
            res = PyInt_AsLong(result);
  -     Py_DECREF(result);
  +     Py_XDECREF(result);
       }
   
       cbInfo->_save = PyEval_SaveThread();
  @@ -285,8 +285,8 @@
   
       args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, 
cbInfo->data);
       result = PyEval_CallObject(cbInfo->cb, args);
  -    Py_DECREF(args);
  -    Py_DECREF(pkgObj);
  +    Py_XDECREF(args);
  +    Py_XDECREF(pkgObj);
   
       if (!result) {
        rpmts_Die(cbInfo->cb);
  @@ -300,7 +300,7 @@
            rpmts_Die(cbInfo->cb);
            /*@notreached@*/
        }
  -     Py_DECREF(result);
  +     Py_XDECREF(result);
        cbInfo->_save = PyEval_SaveThread();
   
        fd = fdDup(fdno);
  @@ -323,7 +323,7 @@
   fprintf(stderr, "\t%llu:%llu key %p\n", (unsigned long long)amount, 
(unsigned long long)total, pkgKey);
       }
   
  -    Py_DECREF(result);
  +    Py_XDECREF(result);
       cbInfo->_save = PyEval_SaveThread();
   
       return NULL;
  @@ -558,6 +558,10 @@
   
       if (ps != NULL) {
        list = PyList_New(0);
  +        if (!list) {
  +              return NULL;
  +        }
  +
        rpmpsi psi = rpmpsInitIterator(ps);
   
        while ((i = rpmpsNextIterator(psi)) >= 0) {
  @@ -622,7 +626,7 @@
            b = _free(b);
   #endif
            PyList_Append(list, (PyObject *) cf);
  -         Py_DECREF(cf);
  +         Py_XDECREF(cf);
        }
   
        psi = rpmpsFreeIterator(psi);
  @@ -712,7 +716,7 @@
            ho = (PyObject *) hdr_Wrap(idt->h);
            tuple = Py_BuildValue("(iOi)", idt->val.u32, ho, idt->instance);
            PyTuple_SET_ITEM(result,  i, tuple);
  -         Py_DECREF(ho);
  +         Py_XDECREF(ho);
        }
       }
   /*@=branchstate@*/
  @@ -765,7 +769,7 @@
            ho = (PyObject *) hdr_Wrap(idt->h);
            tuple = Py_BuildValue("(iOs)", idt->val.u32, ho, idt->key);
            PyTuple_SET_ITEM(result,  i, tuple);
  -         Py_DECREF(ho);
  +         Py_XDECREF(ho);
        }
       }
   /*@=branchstate@*/
  @@ -1283,6 +1287,9 @@
       }
   
       list = PyList_New(0);
  +    if (!list) {
  +     return NULL;
  +    }
       psi = rpmpsInitIterator(ps);
       while (rpmpsNextIterator(psi) >= 0) {
        rpmProblem p = rpmpsProblem(psi);
  @@ -1291,7 +1298,7 @@
                             rpmProblemGetStr(p),
                             PyLong_FromLongLong(rpmProblemGetDiskNeed(p)));
        PyList_Append(list, prob);
  -     Py_DECREF(prob);
  +     Py_XDECREF(prob);
       }
       psi = rpmpsFreeIterator(psi);
   
  @@ -1530,7 +1537,7 @@
       if (s->scriptFd) Fclose(s->scriptFd);
       /* this will free the keyList, and decrement the ref count of all
          the items on the list as well :-) */
  -    Py_DECREF(s->keyList);
  +    Py_XDECREF(s->keyList);
       PyObject_Del((PyObject *)s);
   }
   
  @@ -1591,7 +1598,7 @@
   
       /* this will free the keyList, and decrement the ref count of all
          the items on the list as well :-) */
  -    Py_DECREF(s->keyList);
  +    Py_XDECREF(s->keyList);
   
       PyObject_Del((PyObject *)s);
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/spec-py.c
  ============================================================================
  $ cvs diff -u -r1.14 -r1.15 spec-py.c
  --- rpm/python/spec-py.c      29 Mar 2009 18:42:22 -0000      1.14
  +++ rpm/python/spec-py.c      20 Dec 2011 16:45:56 -0000      1.15
  @@ -120,6 +120,9 @@
       const char * fullSource;
   
       sourceList = PyList_New(0);
  +    if (!sourceList) {
  +        return NULL;
  +    }
       spec = specFromSpec(s);
       if ( spec != NULL) {
           source = spec->sources;
  @@ -127,6 +130,10 @@
            while (source != NULL) {
               fullSource = source->fullSource;
               srcUrl = Py_BuildValue("(sii)", fullSource, source->num, 
source->flags);
  +         if (!srcUrl) {
  +              Py_XDECREF(sourceList);
  +                 return NULL;
  +            }
               PyList_Append(sourceList, srcUrl);
               source = source->next;
           } 
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmpython.c
  ============================================================================
  $ cvs diff -u -r2.16 -r2.17 rpmpython.c
  --- rpm/rpmio/rpmpython.c     30 Apr 2010 23:45:37 -0000      2.16
  +++ rpm/rpmio/rpmpython.c     20 Dec 2011 16:45:57 -0000      2.17
  @@ -178,7 +178,7 @@
                } else
                    *resultp = "";
            }
  -         Py_DECREF(v);
  +         Py_XDECREF(v);
            if (Py_FlushLine())
                PyErr_Clear();
            rc = RPMRC_OK;
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to