Skip to content

Commit

Permalink
dm: virtio: use strnlen instead of strlen
Browse files Browse the repository at this point in the history
Use strnlen instead of strlen to avoid potential security issue.

Tracked-On: #1364
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
chejianj authored and wenlingz committed Oct 10, 2018
1 parent 9bf5aaf commit b1b3f76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion devicemodel/hw/pci/virtio/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <assert.h>
#include <pthread.h>
#include <termios.h>
#include <limits.h>

#include "dm.h"
#include "pci_core.h"
Expand Down Expand Up @@ -326,7 +327,7 @@ virtio_console_announce_port(struct virtio_console_port *port)

event.event = VIRTIO_CONSOLE_PORT_NAME;
virtio_console_control_send(port->console, &event, port->name,
strlen(port->name));
strnlen(port->name, NAME_MAX));
}

static void
Expand Down
3 changes: 2 additions & 1 deletion devicemodel/hw/pci/virtio/virtio_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ virtio_input_get_config(struct virtio_input *vi, uint8_t select,
cfg->u.string);
if (rc >= 0) {
cfg->select = VIRTIO_INPUT_CFG_ID_NAME;
cfg->size = strlen(cfg->u.string);
cfg->size = strnlen(cfg->u.string,
sizeof(cfg->u.string));
found = true;
}
break;
Expand Down

0 comments on commit b1b3f76

Please sign in to comment.