From: Tormod Volden <debian.tor...@gmail.com> The way we retrieve these strings we just have to make sure the buffer is big enough to not truncate the string. I do not know if the USB protocol sets any limit to the string length. If not, a possible TODO would be to add a warning if the returned string filled the buffer. --- src/main.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/main.c b/src/main.c index 0b1cd36..b9b1985 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,9 @@ int verbose = 0; /* If we really have to guess (non-compliant devices) */ #define DEFAULT_TRANSFER_SIZE 1024 +/* Not sure if there is any upper limit */ +#define MAX_ALT_NAME_LEN 1023 + /* define a portable function for reading a 16bit little-endian word */ unsigned short get_int16_le(const void *p) { @@ -188,8 +191,6 @@ static int count_matching_dfu_if(struct dfu_if *dif) return dif->count; } -#define MAX_STR_LEN 64 - /* Retrieves alternate interface name string. * Returns string length, or negative on error */ static int get_alt_name(struct dfu_if *dfu_if, unsigned char *name) @@ -213,7 +214,7 @@ static int get_alt_name(struct dfu_if *dfu_if, unsigned char *name) if (dfu_if->dev_handle) ret = libusb_get_string_descriptor_ascii( dfu_if->dev_handle, alt_name_str_idx, - name, MAX_STR_LEN); + name, MAX_ALT_NAME_LEN); } libusb_free_config_descriptor(cfg); return ret; @@ -221,7 +222,7 @@ static int get_alt_name(struct dfu_if *dfu_if, unsigned char *name) static int print_dfu_if(struct dfu_if *dfu_if, void *v) { - unsigned char name[MAX_STR_LEN+1] = "UNDEFINED"; + unsigned char name[MAX_ALT_NAME_LEN+1] = "UNDEFINED"; get_alt_name(dfu_if, name); @@ -254,7 +255,7 @@ static int list_dfu_interfaces(libusb_context *ctx) static int alt_by_name(struct dfu_if *dfu_if, void *v) { - unsigned char name[MAX_STR_LEN+1]; + unsigned char name[MAX_ALT_NAME_LEN+1]; if (get_alt_name(dfu_if, name) < 0) return 0; @@ -513,7 +514,7 @@ int main(int argc, char **argv) libusb_context *ctx; struct dfu_file file; char *alt_name = NULL; /* query alt name if non-NULL */ - unsigned char active_alt_name[MAX_STR_LEN+1]; + unsigned char active_alt_name[MAX_ALT_NAME_LEN+1]; char *end; int final_reset = 0; int ret; -- 1.7.5.4 _______________________________________________ devel mailing list devel@lists.openmoko.org https://lists.openmoko.org/mailman/listinfo/devel