From: Paweł Szewczyk
Date: Tue, 18 Dec 2018 17:54:32 +0000 (+0100)
Subject: Check validity of API arguments
X-Git-Tag: submit/tizen/20181227.070601~1
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72128f7582c5c37d3100362c10710f52dd814b6e;p=platform%2Fcore%2Fapi%2Fusb-host.git
Check validity of API arguments
Added missing checks of pointers that can be dereferenced.
Change-Id: I217ddd993f540ad0342e984dcb25cf19d76e5842
Signed-off-by: Paweł Szewczyk
---
diff --git a/src/usb_host.c b/src/usb_host.c
index bd7f3ed..d0f6eac 100755
--- a/src/usb_host.c
+++ b/src/usb_host.c
@@ -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;
}