diff options
author | Sergio Aguirre <saaguirre@ti.com> | 2012-04-25 08:57:13 -0500 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2012-04-29 19:30:50 +0200 |
commit | 46bec667b675573cf1ce698c68112e3dbd31930e (patch) | |
tree | 997305e432fcc33b32bd07852cc39934f9e2a4a8 /src/mediactl.c | |
parent | b5a1c3048a028965efe5af46801b9c14959703a2 (diff) |
Compare name length to avoid false positives in media_get_entity_by_name
If two subdevice have names that only differ by a suffix (such as "OMAP4
ISS ISP IPIPE" and "OMAP4 ISS ISP IPIPEIF") the media_get_entity_by_name
function might return a pointer to the entity with the longest name when
called with the shortest name. Fix this by verifying that the candidate
entity name length is equal to the requested name length.
Signed-off-by: Sergio Aguirre <saaguirre@ti.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/mediactl.c')
-rw-r--r-- | src/mediactl.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mediactl.c b/src/mediactl.c index 5b8c587..bc6a713 100644 --- a/src/mediactl.c +++ b/src/mediactl.c @@ -63,10 +63,17 @@ struct media_entity *media_get_entity_by_name(struct media_device *media, { unsigned int i; + /* A match is impossible if the entity name is longer than the maximum + * size we can get from the kernel. + */ + if (length >= FIELD_SIZEOF(struct media_entity_desc, name)) + return NULL; + for (i = 0; i < media->entities_count; ++i) { struct media_entity *entity = &media->entities[i]; - if (strncmp(entity->info.name, name, length) == 0) + if (strncmp(entity->info.name, name, length) == 0 && + entity->info.name[length] == '\0') return entity; } |