Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8c9d5dc authored by Raj Mojumder's avatar Raj Mojumder
Browse files

Add timeout to usb_device_get_string_ucs2 invocation to prevent potential

unbounded stuck state.

Consistent with other usages of usb_device_get_string (that calls
usb_device_get_string_ucs2) employing 200ms timeout values.

Bug:   b/113581955
Test:  Built and tested the code path.
Change-Id: I9fd0305ed4f6bffae16fd08f83f57ccac6c72de1
parent 0e57c50d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <usbhost/usbhost.h>

#define MAX_DESCRIPTORS_LENGTH 4096
static const int USB_CONTROL_TRANSFER_TIMEOUT_MS = 200;

// com.android.server.usb.descriptors
extern "C" {
@@ -85,7 +86,8 @@ jstring JNICALL Java_com_android_server_usb_descriptors_UsbDescriptorParser_getD
    jbyte* byteBuffer = NULL;
    size_t numUSC2Bytes = 0;
    int retVal =
            usb_device_get_string_ucs2(device, stringId, 0 /*timeout*/,
            usb_device_get_string_ucs2(device, stringId,
                                       USB_CONTROL_TRANSFER_TIMEOUT_MS,
                                       (void**)&byteBuffer, &numUSC2Bytes);

    jstring j_str = NULL;