summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-12-20 16:33:50 +0100
committerJose M. Guisado <jguisado@soleta.eu>2022-12-20 16:33:50 +0100
commit88c7374db2309e708e9f9713a3d55acb1472f339 (patch)
treeb3c15ed1f76ac421a54e4da373aabb81206ef9db
parent99a98f92365f28c8e0050fc406dc3cdb0beac236 (diff)
context: check self->cxt and rc in assign_device
Assert self->cxt before calling libfdisk fdisk_assign_device. Also check for its return code and raise exception if libfdisk report any error assigning the device.
-rw-r--r--context.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/context.c b/context.c
index 0248bb3..04eb113 100644
--- a/context.c
+++ b/context.c
@@ -84,9 +84,14 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = { "readonly", NULL };
- int readonly = 0;
+ int rc, readonly = 0;
char *fname;
+ if (!self->cxt) {
+ PyErr_SetString(PyExc_TypeError, ARG_ERR);
+ return NULL;
+ }
+
if (!PyArg_ParseTupleAndKeywords(args,
kwds, "s|p", kwlist,
&readonly)) {
@@ -94,7 +99,10 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
return NULL;
}
- fdisk_assign_device(self->cxt, fname, readonly);
+ if ((rc = fdisk_assign_device(self->cxt, fname, readonly)) < 0) {
+ set_PyErr_from_rc(-rc);
+ return NULL;
+ }
fdisk_get_partitions(self->cxt, &self->tb);
Py_INCREF(Py_None);