PATCH: pyparted: Do not make python process die on an assert

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

 



Hi all,

If you are having python die on a NULL pointer assert in PyString_FromString(),
you will want to do a build of pyparted with the attached patch applied and put
the resulting _pedmodule.so in your updates.img

This happens when parted throws a PED_EXCEPTION_NO_FEATURE exception which it
does for example when you have a partition which does not start on a cylinder
boundary (which was the problem I hit).

Regards,

Hans

p.s.

dcantrell, I've also filed this with pyparted upstream as requested.

>From 552b4e09f629e360b544cb205fad026097e4f107 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@xxxxxxxxxx>
Date: Fri, 27 Feb 2009 14:35:05 +0100
Subject: [PATCH] Replace PyErr_ExceptionMatches() with PyErr_Occurred()

In various places we check wether the libparted exception handler was called
when we got an error return from libparted. We then check to see if
our custom libarted exceptionhandler has already defined an exception, using
PyErr_ExceptionMatches(PartedException), if it has not already defined an
exception, then it should have set partedExnMessage, and we define our
own exception using partedExnMessage.

However our custom libarted exceptionhandler will also define exceptions of
the PyExc_NotImplementedError type, in which case our custom libparted
exceptionhandler has not set partedExnMessage. However as
PyErr_ExceptionMatches(PartedException) does not catch the
PyExc_NotImplementedError case, we still define our own exception using
partedExnMessage, this causes us to call PyErr_SetString() with a NULL
pointer which triggers in assert inside python's C-code.

This patch avoids triggering this assert by using PyErr_Occurred() instead of
PyErr_ExceptionMatches() to see if our custom libparted
exceptionhandler has already defined an exception.
---
 src/convert.c      |   10 ++++------
 src/pyconstraint.c |    2 +-
 src/pydevice.c     |   16 ++++++++--------
 src/pydisk.c       |   38 +++++++++++++++++++-------------------
 src/pyfilesys.c    |   15 ++++++---------
 src/pygeom.c       |   16 ++++++++--------
 6 files changed, 46 insertions(+), 51 deletions(-)

diff --git a/src/convert.c b/src/convert.c
index 2ad4f9b..8872914 100644
--- a/src/convert.c
+++ b/src/convert.c
@@ -398,13 +398,11 @@ PedFileSystem *_ped_FileSystem2PedFileSystem(PyObject *s) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (PyErr_ExceptionMatches(PartedException) ||
-                    PyErr_ExceptionMatches(PyExc_NotImplementedError))
-                    return NULL;
-
-                PyErr_SetString(FileSystemException, partedExnMessage);
-                return NULL;
+                if (!PyErr_Occurred())
+                    PyErr_SetString(FileSystemException, partedExnMessage);
             }
+            else
+                PyErr_SetString(FileSystemException, "Unknown error opening filesystem");
         }
 
         return ret;
diff --git a/src/pyconstraint.c b/src/pyconstraint.c
index df268e8..977c614 100644
--- a/src/pyconstraint.c
+++ b/src/pyconstraint.c
@@ -442,7 +442,7 @@ PyObject *py_ped_constraint_solve_max(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(ConstraintException, partedExnMessage);
         }
         else
diff --git a/src/pydevice.c b/src/pydevice.c
index 7aaf135..ab0cda9 100644
--- a/src/pydevice.c
+++ b/src/pydevice.c
@@ -326,7 +326,7 @@ PyObject *py_ped_device_open(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -368,7 +368,7 @@ PyObject *py_ped_device_close(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -442,7 +442,7 @@ PyObject *py_ped_device_begin_external_access(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -479,7 +479,7 @@ PyObject *py_ped_device_end_external_access(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -530,7 +530,7 @@ PyObject *py_ped_device_read(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -581,7 +581,7 @@ PyObject *py_ped_device_write(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -617,7 +617,7 @@ PyObject *py_ped_device_sync(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -657,7 +657,7 @@ PyObject *py_ped_device_sync_fast(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
diff --git a/src/pydisk.c b/src/pydisk.c
index 8c8e1df..d60037b 100644
--- a/src/pydisk.c
+++ b/src/pydisk.c
@@ -160,7 +160,7 @@ int _ped_Partition_init(_ped_Partition *self, PyObject *args, PyObject *kwds) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException)) {
+            if (!PyErr_Occurred()) {
                 PyErr_SetString(PartitionException, partedExnMessage);
             }
         } else {
@@ -334,7 +334,7 @@ int _ped_Disk_init(_ped_Disk *self, PyObject *args, PyObject *kwds) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException)) {
+            if (!PyErr_Occurred()) {
                 PyErr_SetString(IOException, partedExnMessage);
             }
         } else {
@@ -545,7 +545,7 @@ PyObject *py_ped_disk_duplicate(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(IOException, partedExnMessage);
             }
             else
@@ -601,7 +601,7 @@ PyObject *py_ped_disk_commit(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(IOException, partedExnMessage);
             }
             else
@@ -632,7 +632,7 @@ PyObject *py_ped_disk_commit_to_dev(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(IOException, partedExnMessage);
             }
             else
@@ -663,7 +663,7 @@ PyObject *py_ped_disk_commit_to_os(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(IOException, partedExnMessage);
             }
             else
@@ -694,7 +694,7 @@ PyObject *py_ped_disk_check(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(IOException, partedExnMessage);
             }
             else
@@ -839,7 +839,7 @@ PyObject *py_ped_partition_set_flag(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(PartitionException, partedExnMessage);
             }
             else
@@ -978,7 +978,7 @@ PyObject *py_ped_partition_set_name(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(PartitionException, partedExnMessage);
             }
             else
@@ -1019,7 +1019,7 @@ PyObject *py_ped_partition_get_name(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(PartitionException, partedExnMessage);
             }
             else
@@ -1167,7 +1167,7 @@ PyObject *py_ped_disk_add_partition(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1214,7 +1214,7 @@ PyObject *py_ped_disk_remove_partition(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1255,7 +1255,7 @@ PyObject *py_ped_disk_delete_partition(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1282,7 +1282,7 @@ PyObject *py_ped_disk_delete_all(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(PartitionException, partedExnMessage);
             }
             else
@@ -1340,7 +1340,7 @@ PyObject *py_ped_disk_set_partition_geom(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1391,7 +1391,7 @@ PyObject *py_ped_disk_maximize_partition(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1443,7 +1443,7 @@ PyObject *py_ped_disk_get_max_partition_geometry(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
@@ -1471,7 +1471,7 @@ PyObject *py_ped_disk_minimize_extended_partition(PyObject *s, PyObject *args) {
             if (partedExnRaised) {
                 partedExnRaised = 0;
 
-                if (!PyErr_ExceptionMatches(PartedException))
+                if (!PyErr_Occurred())
                     PyErr_SetString(PartitionException, partedExnMessage);
             }
             else
@@ -1641,7 +1641,7 @@ PyObject *py_ped_disk_new_fresh(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(PartitionException, partedExnMessage);
         }
         else
diff --git a/src/pyfilesys.c b/src/pyfilesys.c
index 2c251cb..f02d4a8 100644
--- a/src/pyfilesys.c
+++ b/src/pyfilesys.c
@@ -270,7 +270,7 @@ PyObject *py_ped_file_system_probe_specific(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -305,7 +305,7 @@ PyObject *py_ped_file_system_probe(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -333,7 +333,7 @@ PyObject *py_ped_file_system_clobber(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -402,8 +402,7 @@ PyObject *py_ped_file_system_create(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PyExc_NotImplementedError) &&
-                !PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(FileSystemException, partedExnMessage);
         }
         else
@@ -536,8 +535,7 @@ PyObject *py_ped_file_system_copy(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PyExc_NotImplementedError) &&
-                !PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(FileSystemException, partedExnMessage);
         }
         else
@@ -593,8 +591,7 @@ PyObject *py_ped_file_system_resize(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PyExc_NotImplementedError) &&
-                !PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(FileSystemException, partedExnMessage);
         }
         else
diff --git a/src/pygeom.c b/src/pygeom.c
index cda3d24..737ae38 100644
--- a/src/pygeom.c
+++ b/src/pygeom.c
@@ -113,7 +113,7 @@ int _ped_Geometry_init(_ped_Geometry *self, PyObject *args, PyObject *kwds) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException)) {
+            if (!PyErr_Occurred()) {
                 PyErr_SetString(CreateException, partedExnMessage);
             }
         } else {
@@ -201,7 +201,7 @@ PyObject *py_ped_geometry_duplicate(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(CreateException, partedExnMessage);
         }
         else
@@ -240,7 +240,7 @@ PyObject *py_ped_geometry_intersect(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(CreateException, partedExnMessage);
         }
         else
@@ -271,7 +271,7 @@ PyObject *py_ped_geometry_set(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(CreateException, partedExnMessage);
         }
         else
@@ -310,7 +310,7 @@ PyObject *py_ped_geometry_set_start(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(CreateException, partedExnMessage);
         }
         else
@@ -348,7 +348,7 @@ PyObject *py_ped_geometry_set_end(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(CreateException, partedExnMessage);
         }
         else
@@ -509,7 +509,7 @@ PyObject *py_ped_geometry_read(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
@@ -601,7 +601,7 @@ PyObject *py_ped_geometry_write(PyObject *s, PyObject *args) {
         if (partedExnRaised) {
             partedExnRaised = 0;
 
-            if (!PyErr_ExceptionMatches(PartedException))
+            if (!PyErr_Occurred())
                 PyErr_SetString(IOException, partedExnMessage);
         }
         else
-- 
1.6.1.3


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux