Commit d0ebf307 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

V4L/DVB (10293): uvcvideo: replace strn{cpy,cat} with strl{cpy,cat}.

strncpy is unsafe as it doesn't append a terminating NUL character when the
source string doesn't fit in the destination buffer. Replace it with strlcpy.
strncat is misused as its size argument refers to the source string, not the
destination buffer. Replace it with strlcat.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 07f7db4c
...@@ -786,7 +786,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video, ...@@ -786,7 +786,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
v4l2_ctrl->id = mapping->id; v4l2_ctrl->id = mapping->id;
v4l2_ctrl->type = mapping->v4l2_type; v4l2_ctrl->type = mapping->v4l2_type;
strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
v4l2_ctrl->flags = 0; v4l2_ctrl->flags = 0;
if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR)) if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
......
...@@ -314,7 +314,7 @@ static int uvc_parse_format(struct uvc_device *dev, ...@@ -314,7 +314,7 @@ static int uvc_parse_format(struct uvc_device *dev,
fmtdesc = uvc_format_by_guid(&buffer[5]); fmtdesc = uvc_format_by_guid(&buffer[5]);
if (fmtdesc != NULL) { if (fmtdesc != NULL) {
strncpy(format->name, fmtdesc->name, strlcpy(format->name, fmtdesc->name,
sizeof format->name); sizeof format->name);
format->fcc = fmtdesc->fcc; format->fcc = fmtdesc->fcc;
} else { } else {
...@@ -345,7 +345,7 @@ static int uvc_parse_format(struct uvc_device *dev, ...@@ -345,7 +345,7 @@ static int uvc_parse_format(struct uvc_device *dev,
return -EINVAL; return -EINVAL;
} }
strncpy(format->name, "MJPEG", sizeof format->name); strlcpy(format->name, "MJPEG", sizeof format->name);
format->fcc = V4L2_PIX_FMT_MJPEG; format->fcc = V4L2_PIX_FMT_MJPEG;
format->flags = UVC_FMT_FLAG_COMPRESSED; format->flags = UVC_FMT_FLAG_COMPRESSED;
format->bpp = 0; format->bpp = 0;
...@@ -363,13 +363,13 @@ static int uvc_parse_format(struct uvc_device *dev, ...@@ -363,13 +363,13 @@ static int uvc_parse_format(struct uvc_device *dev,
switch (buffer[8] & 0x7f) { switch (buffer[8] & 0x7f) {
case 0: case 0:
strncpy(format->name, "SD-DV", sizeof format->name); strlcpy(format->name, "SD-DV", sizeof format->name);
break; break;
case 1: case 1:
strncpy(format->name, "SDL-DV", sizeof format->name); strlcpy(format->name, "SDL-DV", sizeof format->name);
break; break;
case 2: case 2:
strncpy(format->name, "HD-DV", sizeof format->name); strlcpy(format->name, "HD-DV", sizeof format->name);
break; break;
default: default:
uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
...@@ -379,7 +379,7 @@ static int uvc_parse_format(struct uvc_device *dev, ...@@ -379,7 +379,7 @@ static int uvc_parse_format(struct uvc_device *dev,
return -EINVAL; return -EINVAL;
} }
strncat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz", strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
sizeof format->name); sizeof format->name);
format->fcc = V4L2_PIX_FMT_DV; format->fcc = V4L2_PIX_FMT_DV;
...@@ -1526,7 +1526,7 @@ static int uvc_register_video(struct uvc_device *dev) ...@@ -1526,7 +1526,7 @@ static int uvc_register_video(struct uvc_device *dev)
vdev->minor = -1; vdev->minor = -1;
vdev->fops = &uvc_fops; vdev->fops = &uvc_fops;
vdev->release = video_device_release; vdev->release = video_device_release;
strncpy(vdev->name, dev->name, sizeof vdev->name); strlcpy(vdev->name, dev->name, sizeof vdev->name);
/* Set the driver data before calling video_register_device, otherwise /* Set the driver data before calling video_register_device, otherwise
* uvc_v4l2_open might race us. * uvc_v4l2_open might race us.
...@@ -1621,7 +1621,7 @@ static int uvc_probe(struct usb_interface *intf, ...@@ -1621,7 +1621,7 @@ static int uvc_probe(struct usb_interface *intf,
dev->quirks = id->driver_info | uvc_quirks_param; dev->quirks = id->driver_info | uvc_quirks_param;
if (udev->product != NULL) if (udev->product != NULL)
strncpy(dev->name, udev->product, sizeof dev->name); strlcpy(dev->name, udev->product, sizeof dev->name);
else else
snprintf(dev->name, sizeof dev->name, snprintf(dev->name, sizeof dev->name,
"UVC Camera (%04x:%04x)", "UVC Camera (%04x:%04x)",
......
...@@ -55,7 +55,7 @@ static int uvc_v4l2_query_menu(struct uvc_video_device *video, ...@@ -55,7 +55,7 @@ static int uvc_v4l2_query_menu(struct uvc_video_device *video,
return -EINVAL; return -EINVAL;
menu_info = &mapping->menu_info[query_menu->index]; menu_info = &mapping->menu_info[query_menu->index];
strncpy(query_menu->name, menu_info->name, 32); strlcpy(query_menu->name, menu_info->name, sizeof query_menu->name);
return 0; return 0;
} }
...@@ -486,9 +486,9 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -486,9 +486,9 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
struct v4l2_capability *cap = arg; struct v4l2_capability *cap = arg;
memset(cap, 0, sizeof *cap); memset(cap, 0, sizeof *cap);
strncpy(cap->driver, "uvcvideo", sizeof cap->driver); strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
strncpy(cap->card, vdev->name, 32); strlcpy(cap->card, vdev->name, sizeof cap->card);
strncpy(cap->bus_info, video->dev->udev->bus->bus_name, strlcpy(cap->bus_info, video->dev->udev->bus->bus_name,
sizeof cap->bus_info); sizeof cap->bus_info);
cap->version = DRIVER_VERSION_NUMBER; cap->version = DRIVER_VERSION_NUMBER;
if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
...@@ -620,7 +620,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -620,7 +620,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
memset(input, 0, sizeof *input); memset(input, 0, sizeof *input);
input->index = index; input->index = index;
strncpy(input->name, iterm->name, sizeof input->name); strlcpy(input->name, iterm->name, sizeof input->name);
if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA) if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA)
input->type = V4L2_INPUT_TYPE_CAMERA; input->type = V4L2_INPUT_TYPE_CAMERA;
break; break;
...@@ -682,7 +682,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -682,7 +682,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
fmt->flags = 0; fmt->flags = 0;
if (format->flags & UVC_FMT_FLAG_COMPRESSED) if (format->flags & UVC_FMT_FLAG_COMPRESSED)
fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
strncpy(fmt->description, format->name, strlcpy(fmt->description, format->name,
sizeof fmt->description); sizeof fmt->description);
fmt->description[sizeof fmt->description - 1] = 0; fmt->description[sizeof fmt->description - 1] = 0;
fmt->pixelformat = format->fcc; fmt->pixelformat = format->fcc;
......
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