Check validity of API arguments 37/195837/2
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Tue, 18 Dec 2018 17:54:32 +0000 (18:54 +0100)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 20 Dec 2018 16:14:50 +0000 (17:14 +0100)
Added missing checks of pointers that can be dereferenced.

Change-Id: I217ddd993f540ad0342e984dcb25cf19d76e5842
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/usb_host.c

index bd7f3ed8d61eb3f33a30b466452acae3c4b9de6f..d0f6eac97edb229de565774f91940ec52f0b0ea1 100755 (executable)
@@ -979,7 +979,7 @@ int usb_host_claim_interface(usb_host_interface_h interface, bool force)
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!interface) {
+       if (!interface || !interface->altsettings) {
                _E("Invalid parameter");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -1048,7 +1048,7 @@ int usb_host_release_interface(usb_host_interface_h interface)
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!interface) {
+       if (!interface || !interface->altsettings) {
                _E("Invalid parameter was passed");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -1373,7 +1373,7 @@ int usb_host_interface_get_number(usb_host_interface_h interface, int *number)
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!interface || !number) {
+       if (!interface || !interface->altsettings || !number) {
                _E("Invalid parameter was passed");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -1387,7 +1387,7 @@ int usb_host_interface_get_num_endpoints(usb_host_interface_h interface, int *nu
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!interface || !num_endpoints) {
+       if (!interface || !interface->altsettings || !num_endpoints) {
                _E("Invalid parameter was passed");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -1824,7 +1824,7 @@ int usb_host_set_hotplug_cb(usb_host_context_h ctx, usb_host_hotplug_cb cb, usb_
        if (!usb_host_feature_enabled()) //LCOV_EXCL_LINE Not supported feature
                return USB_HOST_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE Not supported feature
 
-       if (!cb)
+       if (!ctx || !cb || !handle)
                return USB_HOST_ERROR_INVALID_PARAMETER;
 
        data = calloc(1, sizeof(*data));
@@ -1892,6 +1892,11 @@ static void generic_transfer_cb(struct libusb_transfer *lusb_transfer)
 {
        struct async_transfer_data *data;
 
+       if (!lusb_transfer) {
+               _E("Invalid parameter");
+               return;
+       }
+
        data = lusb_transfer->user_data;
        data->cb(data->transfer, data->user_data);
 }
@@ -1907,7 +1912,7 @@ int usb_host_create_isochronous_transfer(usb_host_endpoint_h ep, usb_host_transf
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!ep || !data || !transfer) {
+       if (!ep || !data || !transfer || !callback) {
                _E("Invalid parameter");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -1987,7 +1992,7 @@ int usb_host_create_control_transfer(usb_host_device_h dev, usb_host_transferred
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!dev || !data || !transfer) {
+       if (!dev || !data || !transfer || !callback) {
                _E("Invalid parameter");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }
@@ -2168,7 +2173,7 @@ int usb_host_transfer_set_data(usb_host_transfer_h transfer, unsigned char *data
        if (!usb_host_feature_enabled())
                return USB_HOST_ERROR_NOT_SUPPORTED;
 
-       if (!transfer || !transfer->lusb_transfer) {
+       if (!transfer || !transfer->lusb_transfer || !data) {
                _E("Invalid parameter");
                return USB_HOST_ERROR_INVALID_PARAMETER;
        }