]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Fix potential SEGV when accesing File attributes
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Mar 2023 10:35:51 +0000 (10:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Mar 2023 10:35:51 +0000 (10:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/file.c

index 371708923a7be812ca8338ea0cd2e2b49bd0cff6..100a4e515b2ff79d9b3eca410dd2f87434eb6601 100644 (file)
@@ -75,6 +75,8 @@ static PyObject* File_repr(FileObject* self) {
 
 static PyObject* File_get_path(FileObject* self) {
        const char* path = pakfire_file_get_path(self->file);
+       if (!path)
+               Py_RETURN_NONE;
 
        return PyUnicode_FromString(path);
 }
@@ -111,6 +113,8 @@ static PyObject* File_get_type(FileObject* self) {
 
 static PyObject* File_get_uname(FileObject* self) {
        const char* uname = pakfire_file_get_uname(self->file);
+       if (!uname)
+               Py_RETURN_NONE;
 
        return PyUnicode_FromString(uname);
 }
@@ -126,6 +130,8 @@ static int File_set_uname(FileObject* self, PyObject* value) {
 
 static PyObject* File_get_gname(FileObject* self) {
        const char* gname = pakfire_file_get_gname(self->file);
+       if (!gname)
+               Py_RETURN_NONE;
 
        return PyUnicode_FromString(gname);
 }
@@ -236,6 +242,8 @@ static PyObject* File_digest(FileObject* self, PyObject* args) {
 
 static PyObject* File_get_mimetype(FileObject* self) {
        const char* mimetype = pakfire_file_get_mimetype(self->file);
+       if (!mimetype)
+               Py_RETURN_NONE;
 
        return PyUnicode_FromString(mimetype);
 }