libisu: properly handle nulls in isu_pkg_get_name/isu_pkg_get_version 11/318111/1
authorAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 24 Sep 2024 17:20:42 +0000 (19:20 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 24 Sep 2024 17:20:42 +0000 (19:20 +0200)
This commit fixes the incorrect dereferencing of pointers when
retrieving data from the name/version members of the pkg_info
structure in the isu_pkg_get_name/isu_pkg_get_version functions
of the libisu public API.

Although a situation where an instance of the pkg_info structure is
correctly allocated, but its name/version components are NULL, should
not occur during normal usage, public functions must be resilient to
such malformed arguments and respond with an appropriate error rather
than a segfault.

Change-Id: I641b003568a0db79eab79f192c2f612bb6900721

src/libisu/libisu.c

index a2847dabdbe81830766a679e34edbb687bc4baa7..0c2faa0d585aae00b0cd713dbe6a6061949b7e88 100644 (file)
@@ -104,6 +104,10 @@ isu_result isu_pkg_get_name(isu_pkg_info pkg_info, char *name, size_t len)
 
     struct _isu_pkg_info* pkg_info_i = (struct _isu_pkg_info*)pkg_info;
 
+    if (pkg_info_i->name == NULL) {
+        return ISU_RES_ERR_INTERNAL;
+    }
+
     if (len < strlen(pkg_info_i->name)) {
         return ISU_RES_ERR_BUFF_TOO_SMALL;
     }
@@ -123,6 +127,10 @@ isu_result isu_pkg_get_version(isu_pkg_info pkg_info, char *version, size_t len)
 
     struct _isu_pkg_info* pkg_info_i = (struct _isu_pkg_info*)pkg_info;
 
+    if (pkg_info_i->version == NULL) {
+        return ISU_RES_ERR_INTERNAL;
+    }
+
     if (len < strlen(pkg_info_i->version)) {
         return ISU_RES_ERR_BUFF_TOO_SMALL;
     }