Commit b8018b97 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Martin K. Petersen

scsi: scsi_devinfo: fixup string compare

When checking the model and vendor string we need to use the minimum
value of either string, otherwise we'll miss out on wildcard matches.

And we should take care when matching with zero size strings; results
might be unpredictable.  With this patch the rules for matching devinfo
strings are as follows:

- Vendor strings must match exactly
- Empty Model strings will only match if the devinfo model
  is also empty
- Model strings shorter than the devinfo model string will
  not match

Fixes: 5e7ff2ca ("SCSI: fix new bug in scsi_dev_info_list string matching")
Signed-off-by: default avatarHannes Reinecke <hare@suse.com>
Reviewed-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Reviewed-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 588c902b
...@@ -399,8 +399,8 @@ EXPORT_SYMBOL(scsi_dev_info_list_add_keyed); ...@@ -399,8 +399,8 @@ EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
/** /**
* scsi_dev_info_list_find - find a matching dev_info list entry. * scsi_dev_info_list_find - find a matching dev_info list entry.
* @vendor: vendor string * @vendor: full vendor string
* @model: model (product) string * @model: full model (product) string
* @key: specify list to use * @key: specify list to use
* *
* Description: * Description:
...@@ -415,7 +415,7 @@ static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor, ...@@ -415,7 +415,7 @@ static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
struct scsi_dev_info_list *devinfo; struct scsi_dev_info_list *devinfo;
struct scsi_dev_info_list_table *devinfo_table = struct scsi_dev_info_list_table *devinfo_table =
scsi_devinfo_lookup_by_key(key); scsi_devinfo_lookup_by_key(key);
size_t vmax, mmax; size_t vmax, mmax, mlen;
const char *vskip, *mskip; const char *vskip, *mskip;
if (IS_ERR(devinfo_table)) if (IS_ERR(devinfo_table))
...@@ -454,15 +454,18 @@ static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor, ...@@ -454,15 +454,18 @@ static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
dev_info_list) { dev_info_list) {
if (devinfo->compatible) { if (devinfo->compatible) {
/* /*
* Behave like the older version of get_device_flags. * vendor strings must be an exact match
*/ */
if (memcmp(devinfo->vendor, vskip, vmax) || if (vmax != strlen(devinfo->vendor) ||
(vmax < sizeof(devinfo->vendor) && memcmp(devinfo->vendor, vskip, vmax))
devinfo->vendor[vmax]))
continue; continue;
if (memcmp(devinfo->model, mskip, mmax) ||
(mmax < sizeof(devinfo->model) && /*
devinfo->model[mmax])) * @model specifies the full string, and
* must be larger or equal to devinfo->model
*/
mlen = strlen(devinfo->model);
if (mmax < mlen || memcmp(devinfo->model, mskip, mlen))
continue; continue;
return devinfo; return devinfo;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment