Forráskód Böngészése

linux-v4l2: added range check for try_connect()

While the current code only ever calls try_connect() with the input
argument 'device' in the range of 0 and MAX_DEVICES, this adds a check
to ensure that future code does not break the following sprintf.

In addition, use snprintf instead of sprintf to ensure that if anything
breaks, the sprintf does not lead to memory corruption. Again, the new
check should already make sure of that, but the additional effort of
using snprintf instead of sprintf is so low that it is worth to have a
little more security in the future.
Frank Löffler 4 éve
szülő
commit
8f3d4b6758
1 módosított fájl, 3 hozzáadás és 1 törlés
  1. 3 1
      plugins/linux-v4l2/v4l2-output.c

+ 3 - 1
plugins/linux-v4l2/v4l2-output.c

@@ -93,7 +93,9 @@ static bool try_connect(void *data, int device)
 	vcam->frame_size = width * height * 2;
 
 	char new_device[16];
-	sprintf(new_device, "/dev/video%d", device);
+	if (device < 0 || device >= MAX_DEVICES)
+		return false;
+	snprintf(new_device, 16, "/dev/video%d", device);
 
 	vcam->device = open(new_device, O_RDWR);