Bug 58583 - rpmmodule.c causes segfault in verify file
Summary: rpmmodule.c causes segfault in verify file
Keywords:
Status: CLOSED DUPLICATE of bug 58576
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm-python
Version: 1.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-01-20 20:03 UTC by Michael Lipp
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-01-29 21:17:47 UTC
Embargoed:


Attachments (Terms of Use)

Description Michael Lipp 2002-01-20 20:03:36 UTC
Description of Problem:

verifyFile in rpmmodule.c causes segmentation fault when user or group has changed.

Version-Release number of selected component (if applicable):

rpm-python-4.0.3-1.03

How Reproducible:

Just call it for a file with user or group modified after installation

Additional Information:
	
A patch that fixes the segfaults and tries to provide a solution is appended.

Comment 1 Michael Lipp 2002-01-20 20:09:04 UTC
Creating attachment failed, here is the patch

*** rpmmodule.c.orig	Sun Jan 20 13:22:02 2002
--- rpmmodule.c	Sun Jan 20 20:29:23 2002
***************
*** 123,128 ****
--- 123,129 ----
      int_32 * fileSizes;
      int_32 * mtimes;
      int_32 * uids, * gids;	/* XXX these tags are not used anymore */
+     char ** unames, ** gnames;
      unsigned short * rdevs;
      unsigned short * modes;
  } ;
***************
*** 343,362 ****
       * XXX Consistent? rpmlib.a verifies user/group quite well, thank you.
       * XXX The code below does nothing useful. FILEUSERNAME needs to be
       * XXX retrieved and looked up.
       */
      if (verifyResult & RPMVERIFY_USER) {
- 	if (!s->uids) {
- 	    headerGetEntry(s->h, RPMTAG_FILEUIDS, &type, (void **) &s->uids,
- 		     &count);
- 	}
- 
  	tuple = PyTuple_New(3);
! 	attrName = PyString_FromString("uid");
! 	PyTuple_SetItem(tuple, 0, attrName);
! 	sprintf(buf, "%d", s->uids[fileNumber]);
! 	PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	sprintf(buf, "%d", sb.st_uid);
! 	PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
--- 344,382 ----
       * XXX Consistent? rpmlib.a verifies user/group quite well, thank you.
       * XXX The code below does nothing useful. FILEUSERNAME needs to be
       * XXX retrieved and looked up.
+      *
+      * YYY Modified code to eliminate the core dumps. Don't know if this
+      * YYY is what it aught to be, though.
       */
      if (verifyResult & RPMVERIFY_USER) {
  	tuple = PyTuple_New(3);
! 	if (s->uids 
! 	    || headerGetEntry(s->h, RPMTAG_FILEUIDS, &type, (void **) &s->uids,
! 	
	      &count)) {
!             attrName = PyString_FromString("uid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    sprintf(buf, "%d", s->uids[fileNumber]);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	    sprintf(buf, "%d", sb.st_uid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
! 	else if (s->unames
! 		 || headerGetEntry(s->h, RPMTAG_FILEUSERNAME, NULL, 
! 	
		   (void **) &s->unames, NULL)) {
! 	    char *name = uidToUname(sb.st_uid);
! 	    attrName = PyString_FromString("username");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, 
! 	
	    PyString_FromString(s->unames[fileNumber]));
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(name));
! 	}
! 	else {
!             attrName = PyString_FromString("uid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString("(unknown)"));
! 	    sprintf(buf, "%d", sb.st_uid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
***************
*** 364,383 ****
      /*
       * XXX The code below does nothing useful. FILEGROUPNAME needs to be
       * XXX retrieved and looked up.
       */
      if (verifyResult & RPMVERIFY_GROUP) {
-	if (!s->gids) {
- 	    headerGetEntry(s->h, RPMTAG_FILEGIDS, &type, (void **) &s->gids,
- 		     &count);
- 	}
- 
  	tuple = PyTuple_New(3);
! 	attrName = PyString_FromString("gid");
! 	PyTuple_SetItem(tuple, 0, attrName);
! 	sprintf(buf, "%d", s->gids[fileNumber]);
! 	PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	sprintf(buf, "%d", sb.st_gid);
! 	PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
--- 384,422 ----
      /*
       * XXX The code below does nothing useful. FILEGROUPNAME needs to be
       * XXX retrieved and looked up.
+      *
+      * YYY Modified code to eliminate the core dumps. Don't know if this
+      * YYY is what it aught to be, though.
       */
      if (verifyResult & RPMVERIFY_GROUP) {
  	tuple = PyTuple_New(3);
! 	if (s->gids
! 	    || headerGetEntry(s->h, RPMTAG_FILEGIDS, &type, (void **) &s->gids,
! 	
	      &count)) {
! 	    attrName = PyString_FromString("gid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    sprintf(buf, "%d", s->gids[fileNumber]);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	    sprintf(buf, "%d", sb.st_gid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
! 	else if (s->gnames
! 		 || headerGetEntry(s->h, RPMTAG_FILEGROUPNAME, NULL, 
! 	
		   (void **) &s->gnames, NULL)) {
! 	    char * group = gidToGname(sb.st_gid);
! 	    attrName = PyString_FromString("groupname");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, 
! 	
	    PyString_FromString(s->gnames[fileNumber]));
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(group));
! 	}
! 	else {
!             attrName = PyString_FromString("gid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString("(unknown)"));
! 	    sprintf(buf, "%d", sb.st_gid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
***************
*** 511,517 ****
  static struct PyMethodDef hdrMethods[] = {
  	{"keys",	(PyCFunction) hdrKeyList,	1 },
  	{"unload",	(PyCFunction) hdrUnload,	METH_VARARGS|METH_KEYWORDS },
! 	{"verifyFile",	(PyCFunction) hdrVerifyFile,	1 },
  	{"expandFilelist",	(PyCFunction) hdrExpandFilelist,	1 },
  	{"compressFilelist",	(PyCFunction) hdrCompressFilelist,	1 },
  	{"fullFilelist",	(PyCFunction) hdrFullFilelist,	1 },
--- 550,556 ----
  static struct PyMethodDef hdrMethods[] = {
  	{"keys",	(PyCFunction) hdrKeyList,	1 },
  	{"unload",	(PyCFunction) hdrUnload,	METH_VARARGS|METH_KEYWORDS },
! 	{"verifyFile",	(PyCFunction) hdrVerifyFile,	0 },
  	{"expandFilelist",	(PyCFunction) hdrExpandFilelist,	1 },
  	{"compressFilelist",	(PyCFunction) hdrCompressFilelist,	1 },
  	{"fullFilelist",	(PyCFunction) hdrFullFilelist,	1 },
***************
*** 533,538 ****
--- 572,579 ----
      if (s->md5list) free(s->md5list);
      if (s->fileList) free(s->fileList);
      if (s->linkList) free(s->linkList);
+     if (s->unames) free(s->unames);
+     if (s->gnames) free(s->gnames);
      PyMem_DEL(s);
  }
  
***************
*** 791,796 ****
--- 832,838 ----
      ho->sigs = NULL;
      ho->fileList = ho->linkList = ho->md5list = NULL;
      ho->uids = ho->gids = ho->mtimes = ho->fileSizes = NULL;
+     ho->unames = ho->gnames = NULL;
      ho->modes = ho->rdevs = NULL;
      
      return (PyObject *) ho;
***************
*** 1123,1128 ****
--- 1165,1171 ----
      }
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
      if (!h->h) {
  	Py_DECREF(h);
***************
*** 1820,1825 ****
--- 1863,1869 ----
  	h->sigs = sigs;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	if (headerIsEntry(header, RPMTAG_SOURCEPACKAGE))
  	    isSource = 1;
***************
*** 1872,1877 ****
--- 1916,1922 ----
      h->sigs = NULL;
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
  
      return (PyObject *) h;
***************
*** 1928,1933 ****
--- 1973,1979 ----
      h->sigs = NULL;
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
  
      return (PyObject *) h;
***************
*** 2024,2029 ****
--- 2070,2076 ----
  	h->sigs = NULL;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	if (PyList_Append(list, (PyObject *) h)) {
  	    Py_DECREF(list);
***************
*** 2118,2128 ****
--- 2165,2179 ----
  	if (ho->md5list) free(ho->md5list);
  	if (ho->fileList) free(ho->fileList);
  	if (ho->linkList) free(ho->linkList);
+ 	if (ho->unames) free(ho->unames);
+ 	if (ho->gnames) free(ho->gnames);
  
  	ho->sigs = NULL;
  	ho->md5list = NULL;
  	ho->fileList = NULL;
  	ho->linkList = NULL;
+ 	ho->unames = NULL;
+ 	ho->gnames = NULL;
  
  	iter = headerInitIterator(newH);
  
***************
*** 2309,2314 ****
--- 2360,2366 ----
  	h->sigs = NULL;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	return (PyObject *) h;
      }


Comment 2 Michael Lipp 2002-01-24 21:28:32 UTC
Patch missed non-mappable uids/gids. Here is a better one:

*** rpmmodule.c.orig	Sun Jan 20 13:22:02 2002
--- rpmmodule.c	Thu Jan 24 22:21:26 2002
***************
*** 123,128 ****
--- 123,129 ----
      int_32 * fileSizes;
      int_32 * mtimes;
      int_32 * uids, * gids;	/* XXX these tags are not used anymore */
+     char ** unames, ** gnames;
      unsigned short * rdevs;
      unsigned short * modes;
  } ;
***************
*** 343,362 ****
       * XXX Consistent? rpmlib.a verifies user/group quite well, thank you.
       * XXX The code below does nothing useful. FILEUSERNAME needs to be
       * XXX retrieved and looked up.
       */
      if (verifyResult & RPMVERIFY_USER) {
- 	if (!s->uids) {
- 	    headerGetEntry(s->h, RPMTAG_FILEUIDS, &type, (void **) &s->uids,
- 		     &count);
- 	}
- 
  	tuple = PyTuple_New(3);
! 	attrName = PyString_FromString("uid");
! 	PyTuple_SetItem(tuple, 0, attrName);
! 	sprintf(buf, "%d", s->uids[fileNumber]);
! 	PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	sprintf(buf, "%d", sb.st_uid);
! 	PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
--- 344,378 ----
       * XXX Consistent? rpmlib.a verifies user/group quite well, thank you.
       * XXX The code below does nothing useful. FILEUSERNAME needs to be
       * XXX retrieved and looked up.
+      *
+      * YYY Modified code to eliminate the core dumps. Don't know if this
+      * YYY is what it aught to be, though.
       */
      if (verifyResult & RPMVERIFY_USER) {
  	tuple = PyTuple_New(3);
! 	if (s->unames
! 		 || headerGetEntry(s->h, RPMTAG_FILEUSERNAME, NULL, 
! 	
		   (void **) &s->unames, NULL)) {
! 	    char *name = uidToUname(sb.st_uid);
! 	    attrName = PyString_FromString("username");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, 
! 	
	    PyString_FromString(s->unames[fileNumber]));
! 	    if (name) {
! 	      PyTuple_SetItem(tuple, 2, PyString_FromString(name));
! 	    }
! 	    else {
! 	      sprintf(buf, "%d", sb.st_uid);
! 	      PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	    }
! 	}
! 	else {
!             attrName = PyString_FromString("uid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString("(unknown)"));
! 	    sprintf(buf, "%d", sb.st_uid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
***************
*** 364,383 ****
      /*
       * XXX The code below does nothing useful. FILEGROUPNAME needs to be
       * XXX retrieved and looked up.
       */
      if (verifyResult & RPMVERIFY_GROUP) {
- 	if (!s->gids) {
- 	    headerGetEntry(s->h, RPMTAG_FILEGIDS, &type, (void **) &s->gids,
- 		     &count);
- 	}
- 
  	tuple = PyTuple_New(3);
! 	attrName = PyString_FromString("gid");
! 	PyTuple_SetItem(tuple, 0, attrName);
! 	sprintf(buf, "%d", s->gids[fileNumber]);
! 	PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
! 	sprintf(buf, "%d", sb.st_gid);
! 	PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
--- 380,414 ----
      /*
       * XXX The code below does nothing useful. FILEGROUPNAME needs to be
       * XXX retrieved and looked up.
+      *
+      * YYY Modified code to eliminate the core dumps. Don't know if this
+      * YYY is what it aught to be, though.
       */
      if (verifyResult & RPMVERIFY_GROUP) {
  	tuple = PyTuple_New(3);
! 	if (s->gnames
! 		 || headerGetEntry(s->h, RPMTAG_FILEGROUPNAME, NULL, 
! 	
		   (void **) &s->gnames, NULL)) {
! 	    char * group = gidToGname(sb.st_gid);
! 	    attrName = PyString_FromString("groupname");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, 
! 	
	    PyString_FromString(s->gnames[fileNumber]));
! 	    if (group) {
! 	      PyTuple_SetItem(tuple, 2, PyString_FromString(group));
! 	    }
! 	    else {
! 	      sprintf(buf, "%d", sb.st_gid);
! 	      PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	    }
! 	}
! 	else {
!             attrName = PyString_FromString("gid");
! 	    PyTuple_SetItem(tuple, 0, attrName);
! 	    PyTuple_SetItem(tuple, 1, PyString_FromString("(unknown)"));
! 	    sprintf(buf, "%d", sb.st_gid);
! 	    PyTuple_SetItem(tuple, 2, PyString_FromString(buf));
! 	}
  	PyList_Append(list, tuple);
  	Py_DECREF(tuple);
      }
***************
*** 511,517 ****
  static struct PyMethodDef hdrMethods[] = {
  	{"keys",	(PyCFunction) hdrKeyList,	1 },
  	{"unload",	(PyCFunction) hdrUnload,	METH_VARARGS|METH_KEYWORDS },
! 	{"verifyFile",	(PyCFunction) hdrVerifyFile,	1 },
  	{"expandFilelist",	(PyCFunction) hdrExpandFilelist,	1 },
  	{"compressFilelist",	(PyCFunction) hdrCompressFilelist,	1 },
  	{"fullFilelist",	(PyCFunction) hdrFullFilelist,	1 },
--- 542,548 ----
  static struct PyMethodDef hdrMethods[] = {
  	{"keys",	(PyCFunction) hdrKeyList,	1 },
  	{"unload",	(PyCFunction) hdrUnload,	METH_VARARGS|METH_KEYWORDS },
! 	{"verifyFile",	(PyCFunction) hdrVerifyFile,	0 },
  	{"expandFilelist",	(PyCFunction) hdrExpandFilelist,	1 },
  	{"compressFilelist",	(PyCFunction) hdrCompressFilelist,	1 },
  	{"fullFilelist",	(PyCFunction) hdrFullFilelist,	1 },
***************
*** 533,538 ****
--- 564,571 ----
      if (s->md5list) free(s->md5list);
      if (s->fileList) free(s->fileList);
      if (s->linkList) free(s->linkList);
+     if (s->unames) free(s->unames);
+     if (s->gnames) free(s->gnames);
      PyMem_DEL(s);
  }
  
***************
*** 791,796 ****
--- 824,830 ----
      ho->sigs = NULL;
      ho->fileList = ho->linkList = ho->md5list = NULL;
      ho->uids = ho->gids = ho->mtimes = ho->fileSizes = NULL;
+     ho->unames = ho->gnames = NULL;
      ho->modes = ho->rdevs = NULL;
      
      return (PyObject *) ho;
***************
*** 1123,1128 ****
--- 1157,1163 ----
      }
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
      if (!h->h) {
  	Py_DECREF(h);
***************
*** 1820,1825 ****
--- 1855,1861 ----
  	h->sigs = sigs;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	if (headerIsEntry(header, RPMTAG_SOURCEPACKAGE))
  	    isSource = 1;
***************
*** 1872,1877 ****
--- 1908,1914 ----
      h->sigs = NULL;
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
  
      return (PyObject *) h;
***************
*** 1928,1933 ****
--- 1965,1971 ----
      h->sigs = NULL;
      h->fileList = h->linkList = h->md5list = NULL;
      h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+     h->unames = h->gnames = NULL;
      h->modes = h->rdevs = NULL;
  
      return (PyObject *) h;
***************
*** 2024,2029 ****
--- 2062,2068 ----
  	h->sigs = NULL;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	if (PyList_Append(list, (PyObject *) h)) {
  	    Py_DECREF(list);
***************
*** 2118,2128 ****
--- 2157,2171 ----
  	if (ho->md5list) free(ho->md5list);
  	if (ho->fileList) free(ho->fileList);
  	if (ho->linkList) free(ho->linkList);
+ 	if (ho->unames) free(ho->unames);
+ 	if (ho->gnames) free(ho->gnames);
  
  	ho->sigs = NULL;
  	ho->md5list = NULL;
  	ho->fileList = NULL;
  	ho->linkList = NULL;
+ 	ho->unames = NULL;
+ 	ho->gnames = NULL;
  
  	iter = headerInitIterator(newH);
  
***************
*** 2309,2314 ****
--- 2352,2358 ----
  	h->sigs = NULL;
  	h->fileList = h->linkList = h->md5list = NULL;
  	h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
+ 	h->unames = h->gnames = NULL;
  	h->modes = h->rdevs = NULL;
  	return (PyObject *) h;
      }

Comment 3 Jeff Johnson 2002-08-07 23:20:55 UTC

*** This bug has been marked as a duplicate of 58576 ***


Note You need to log in before you can comment on or make changes to this bug.