virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [patch] virtio_console: use snprintf() for safety
@ 2015-05-08  6:19 Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2015-05-08  6:19 UTC (permalink / raw)
  To: Amit Shah
  Cc: Greg Kroah-Hartman, kernel-janitors, Arnd Bergmann,
	virtualization

My static checker complains that this sprintf() can overflow.

vdev->index is selected by ida_simple_get() in register_virtio_device()
so my reading of the code is that this overflow is theoretically
possible.  The max value of "id" is configurable and I'm not sure what
typical values are.

Anyway, it's simple enough to make the buffer larger and I changed it to
snprintf() as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 50754d20..8283989 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1389,7 +1389,7 @@ static void send_sigio_to_port(struct port *port)
 
 static int add_port(struct ports_device *portdev, u32 id)
 {
-	char debugfs_name[16];
+	char debugfs_name[28];
 	struct port *port;
 	struct port_buffer *buf;
 	dev_t devt;
@@ -1492,8 +1492,8 @@ static int add_port(struct ports_device *portdev, u32 id)
 		 * Finally, create the debugfs file that we can use to
 		 * inspect a port's state at any time
 		 */
-		sprintf(debugfs_name, "vport%up%u",
-			port->portdev->vdev->index, id);
+		snprintf(debugfs_name, sizeof(debugfs_name), "vport%up%u",
+			 port->portdev->vdev->index, id);
 		port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
 							 pdrvdata.debugfs_dir,
 							 port,

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-08 12:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20150508061902.GA14769@mwanda>
2015-05-08  6:31 ` [patch] virtio_console: use snprintf() for safety Amit Shah
2015-05-08  9:16   ` [patch v2] virtio_console: silence a static checker warning Dan Carpenter
2015-05-08  9:29     ` Amit Shah
2015-05-08  9:30     ` walter harms
     [not found]     ` <554C8221.9070304@bfs.de>
2015-05-08  9:47       ` Dan Carpenter
2015-05-08  9:56       ` Amit Shah
     [not found]       ` <20150508095616.GB5527@grmbl.mre>
2015-05-08 11:13         ` walter harms
     [not found]         ` <554C9A52.4030707@bfs.de>
2015-05-08 12:18           ` Dan Carpenter
2015-05-08  6:19 [patch] virtio_console: use snprintf() for safety Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).