Use snprintf instead of sprintf for avoiding risk of overflow.
Change-Id: If420efb9780e615c368400b2de0c05743ec3a5f6
Signed-off-by: Sungchun Kang <sungchun.kang@samsung.com>
char *p;
int ret;
- sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
+ snprintf(sysname, sizeof(sysname), "/sys/dev/char/%u:%u", entity->info.v4l.major,
entity->info.v4l.minor);
ret = readlink(sysname, target, sizeof(target));
if (p == NULL)
return -EINVAL;
- sprintf(devname, "/tmp/%s", p + 1);
+ snprintf(devname, sizeof(devname), "/tmp/%s", p + 1);
ret = mknod(devname, 0666 | S_IFCHR, MKDEV(81, entity->info.v4l.minor));
- strcpy(entity->devname, devname);
+ strncpy(entity->devname, devname, 32);
return 0;
}
break;
/* video device node */
- sprintf(filename, "/dev/v4l-subdev%d", i++);
+ snprintf(filename, sizeof(filename), "/dev/v4l-subdev%d", i++);
/* if the node is video device */
if ((lstat(filename, &s) == 0) && S_ISCHR(s.st_mode) &&
minor = (int)((unsigned short)(s.st_rdev & 0x3f));
ALOGD("try node: %s, minor: %d", filename, minor);
/* open sysfs entry */
- sprintf(filename, "/sys/class/video4linux/v4l-subdev%d/name", minor);
+ snprintf(filename, sizeof(filename), "/sys/class/video4linux/v4l-subdev%d/name", minor);
stream_fd = fopen(filename, "r");
if (stream_fd == NULL) {
ALOGE("failed to open sysfs entry for subdev");
break;
/* video device node */
- sprintf(filename, "/dev/v4l-subdev%d", i++);
+ snprintf(filename, sizeof(filename), "/dev/v4l-subdev%d", i++);
/* if the node is video device */
if ((lstat(filename, &s) == 0) && S_ISCHR(s.st_mode) &&
minor = (int)((unsigned short)(s.st_rdev & 0x3f));
ALOGD("try node: %s, minor: %d", filename, minor);
/* open sysfs entry */
- sprintf(filename, "/sys/class/video4linux/v4l-subdev%d/name", minor);
+ snprintf(filename, sizeof(filename), "/sys/class/video4linux/v4l-subdev%d/name", minor);
stream_fd = fopen(filename, "r");
if (stream_fd == NULL) {
ALOGE("failed to open sysfs entry for subdev");
break;
/* video device node */
- sprintf(filename, "/dev/video%d", i++);
+ snprintf(filename, sizeof(filename), "/dev/video%d", i++);
/* if the node is video device */
if ((lstat(filename, &s) == 0) && S_ISCHR(s.st_mode) &&
minor = (int)((unsigned short)(s.st_rdev & 0x3f));
ALOGD("try node: %s, minor: %d", filename, minor);
/* open sysfs entry */
- sprintf(filename, "/sys/class/video4linux/video%d/name", minor);
+ snprintf(filename, sizeof(filename), "/sys/class/video4linux/video%d/name", minor);
stream_fd = fopen(filename, "r");
if (stream_fd == NULL) {
ALOGE("failed to open sysfs entry for videodev");
}
input.index = index;
- ret = ioctl(fd, VIDIOC_ENUMINPUT, &input);
+ ret = ioctl(fd, VIDIOC_ENUMINPUT, &input, 32);
if (ret) {
ALOGE("%s: no matching index founds", __func__);
return false;
ALOGI("Name of input channel[%d] is %s", input.index, input.name);
- strcpy(input_name_buf, (const char *)input.name);
+ strncpy(input_name_buf, (const char *)input.name, 32);
Exynos_v4l2_Out();