[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Patch] header.verifyFile() in rpmmodule.c



I was looking at the header.verifyFile() function in the python module
and noticed some problems which this patch fixes:

1) It didn't properly parse the python representation of the arguments,
making the function impossible to use.

2) headerGetEntry() didn't seem to be doing the right thing for
RPMTAG_OLDFILENAMES, which led ot potential segfaults.
rpmHeaderGetEntry() seems to fix this.

3) There was no checking of the values passed in.. this would lead to a
segfault if a bad number was used.


The patch does some techniclly unneeded initializations, but I wanted to
be thorough.

This patch is made against rpm-4.0.3-1.03 with my previous patch (adding
.copy() ) applied.  If you cut the initialization parts out of this
patch, it should apply to vanilla rpm-4.0.3-1.03.


Jag
--- rpmmodule.c.orig	Tue Feb  5 22:50:52 2002
+++ rpmmodule.c	Tue Feb  5 22:50:56 2002
@@ -126,6 +126,7 @@
     int_32 * uids, * gids;	/* XXX these tags are not used anymore */
     unsigned short * rdevs;
     unsigned short * modes;
+    int_32 fileCount;
 } ;
 
 /** \ingroup python
@@ -210,12 +211,21 @@
     time_t timeInt;
     struct tm * timeStruct;
 
-    if (!PyInt_Check(args)) {
-	PyErr_SetString(PyExc_TypeError, "integer expected");
+    if (!PyArg_ParseTuple(args, "i", &fileNumber)) {
 	return NULL;
     }
 
-    fileNumber = (int) PyInt_AsLong(args);
+    /* XXX Legacy tag needs to go away. */
+    if (!s->fileList) {
+	rpmHeaderGetEntry(s->h, RPMTAG_OLDFILENAMES, &type, (void **) &s->fileList,
+		 &count);
+	s->fileCount = count;
+    }
+
+    if (fileNumber < 0 || fileNumber >= s->fileCount) {
+	PyErr_SetString(PyExc_ValueError, "invalid file number");
+	return NULL;
+    }
 
     /* XXX this routine might use callbacks intelligently. */
     if (rpmVerifyFile("", s->h, fileNumber, &verifyResult, RPMVERIFY_NONE)) {
@@ -227,12 +237,6 @@
 
     if (!verifyResult) return list;
 
-    /* XXX Legacy tag needs to go away. */
-    if (!s->fileList) {
-	headerGetEntry(s->h, RPMTAG_OLDFILENAMES, &type, (void **) &s->fileList,
-		 &count);
-    }
-
     lstat(s->fileList[fileNumber], &sb);
 
     if (verifyResult & RPMVERIFY_MD5) {
@@ -513,6 +517,7 @@
     newH->fileList = newH->linkList = newH->md5list = NULL;
     newH->uids = newH->gids = newH->mtimes = newH->fileSizes = NULL;
     newH->modes = newH->rdevs = NULL;
+    newH->fileCount = -1;
 
     return (PyObject *) newH;
 }
@@ -944,6 +949,7 @@
     ho->fileList = ho->linkList = ho->md5list = NULL;
     ho->uids = ho->gids = ho->mtimes = ho->fileSizes = NULL;
     ho->modes = ho->rdevs = NULL;
+    ho->fileCount = -1;
     
     return (PyObject *) ho;
 }
@@ -1276,6 +1282,7 @@
     h->fileList = h->linkList = h->md5list = NULL;
     h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
     h->modes = h->rdevs = NULL;
+    h->fileCount = -1;
     if (!h->h) {
 	Py_DECREF(h);
 	PyErr_SetString(pyrpmError, "cannot read rpmdb entry");
@@ -1973,6 +1980,7 @@
 	h->fileList = h->linkList = h->md5list = NULL;
 	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
 	h->modes = h->rdevs = NULL;
+	h->fileCount = -1;
 	if (headerIsEntry(header, RPMTAG_SOURCEPACKAGE))
 	    isSource = 1;
 	break;
@@ -2025,6 +2033,7 @@
     h->fileList = h->linkList = h->md5list = NULL;
     h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
     h->modes = h->rdevs = NULL;
+    h->fileCount = -1;
 
     return (PyObject *) h;
 }
@@ -2081,6 +2090,7 @@
     h->fileList = h->linkList = h->md5list = NULL;
     h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
     h->modes = h->rdevs = NULL;
+    h->fileCount = -1;
 
     return (PyObject *) h;
 }
@@ -2177,6 +2187,7 @@
 	h->fileList = h->linkList = h->md5list = NULL;
 	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
 	h->modes = h->rdevs = NULL;
+	h->fileCount = -1;
 	if (PyList_Append(list, (PyObject *) h)) {
 	    Py_DECREF(list);
 	    Py_DECREF(h);
@@ -2275,6 +2286,7 @@
 	ho->md5list = NULL;
 	ho->fileList = NULL;
 	ho->linkList = NULL;
+	ho->fileCount = -1;
 
 	iter = headerInitIterator(newH);
 
@@ -2462,6 +2474,7 @@
 	h->fileList = h->linkList = h->md5list = NULL;
 	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
 	h->modes = h->rdevs = NULL;
+	h->fileCount = -1;
 	return (PyObject *) h;
     }
     Py_INCREF(Py_None);

Attachment: pgp00003.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []