Re: [PATCH 2/3 v2] media: replace strcpy() by strscpy()

2018-09-11 Thread Hans Verkuil
On 09/10/2018 10:20 PM, Mauro Carvalho Chehab wrote:
> The strcpy() function is being deprecated upstream. Replace
> it by the safer strscpy().
> 
> Signed-off-by: Mauro Carvalho Chehab 

Reviewed-by: Hans Verkuil 

Regards,

Hans



[PATCH 2/3 v2] media: replace strcpy() by strscpy()

2018-09-10 Thread Mauro Carvalho Chehab
The strcpy() function is being deprecated upstream. Replace
it by the safer strscpy().

Signed-off-by: Mauro Carvalho Chehab 

--

v2: removed the changes at the imon driver. There, the is a debugfs
node with a store function using DEVICE_ATTR() passing a char * buf
without any sizing information.

So, for now, keep using strcpy() there.


diff --git a/drivers/media/common/saa7146/saa7146_video.c 
b/drivers/media/common/saa7146/saa7146_video.c
index 77d8fcdd4f66..efbf13c5ab82 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -451,7 +451,7 @@ static int vidioc_querycap(struct file *file, void *fh, 
struct v4l2_capability *
struct video_device *vdev = video_devdata(file);
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
 
-   strcpy((char *)cap->driver, "saa7146 v4l2");
+   strscpy((char *)cap->driver, "saa7146 v4l2", sizeof(cap->driver));
strscpy((char *)cap->card, dev->ext->name, sizeof(cap->card));
sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci));
cap->device_caps =
diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index c4e7ebfe4d29..961207cf09eb 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -2422,7 +2422,7 @@ static int dvb_frontend_handle_ioctl(struct file *file,
struct dvb_frontend_info *info = parg;
memset(info, 0, sizeof(*info));
 
-   strcpy(info->name, fe->ops.info.name);
+   strscpy(info->name, fe->ops.info.name, sizeof(info->name));
info->symbol_rate_min = fe->ops.info.symbol_rate_min;
info->symbol_rate_max = fe->ops.info.symbol_rate_max;
info->symbol_rate_tolerance = 
fe->ops.info.symbol_rate_tolerance;
diff --git a/drivers/media/dvb-frontends/mt312.c 
b/drivers/media/dvb-frontends/mt312.c
index aad07adda37d..03e74a729168 100644
--- a/drivers/media/dvb-frontends/mt312.c
+++ b/drivers/media/dvb-frontends/mt312.c
@@ -815,17 +815,20 @@ struct dvb_frontend *mt312_attach(const struct 
mt312_config *config,
 
switch (state->id) {
case ID_VP310:
-   strcpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S");
+   strscpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S",
+   sizeof(state->frontend.ops.info.name));
state->xtal = MT312_PLL_CLK;
state->freq_mult = 9;
break;
case ID_MT312:
-   strcpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S");
+   strscpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S",
+   sizeof(state->frontend.ops.info.name));
state->xtal = MT312_PLL_CLK;
state->freq_mult = 6;
break;
case ID_ZL10313:
-   strcpy(state->frontend.ops.info.name, "Zarlink ZL10313 DVB-S");
+   strscpy(state->frontend.ops.info.name, "Zarlink ZL10313 DVB-S",
+   sizeof(state->frontend.ops.info.name));
state->xtal = MT312_PLL_CLK_10_111;
state->freq_mult = 9;
break;
diff --git a/drivers/media/dvb-frontends/zl10039.c 
b/drivers/media/dvb-frontends/zl10039.c
index 6293bd920fa6..333e4a1da13b 100644
--- a/drivers/media/dvb-frontends/zl10039.c
+++ b/drivers/media/dvb-frontends/zl10039.c
@@ -288,8 +288,9 @@ struct dvb_frontend *zl10039_attach(struct dvb_frontend *fe,
state->id = state->id & 0x0f;
switch (state->id) {
case ID_ZL10039:
-   strcpy(fe->ops.tuner_ops.info.name,
-   "Zarlink ZL10039 DVB-S tuner");
+   strscpy(fe->ops.tuner_ops.info.name,
+   "Zarlink ZL10039 DVB-S tuner",
+   sizeof(fe->ops.tuner_ops.info.name));
break;
default:
dprintk("Chip ID=%x does not match a known type\n", state->id);
diff --git a/drivers/media/firewire/firedtv-fe.c 
b/drivers/media/firewire/firedtv-fe.c
index 69087ae6c1d0..683957885ac4 100644
--- a/drivers/media/firewire/firedtv-fe.c
+++ b/drivers/media/firewire/firedtv-fe.c
@@ -247,7 +247,7 @@ void fdtv_frontend_init(struct firedtv *fdtv, const char 
*name)
dev_err(fdtv->device, "no frontend for model type %d\n",
fdtv->type);
}
-   strcpy(fi->name, name);
+   strscpy(fi->name, name, sizeof(fi->name));
 
fdtv->fe.dvb = >adapter;
fdtv->fe.sec_priv = fdtv;
diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
index 034ebf754007..907323f0ca3b 100644
--- a/drivers/media/i2c/ad5820.c
+++ b/drivers/media/i2c/ad5820.c
@@ -317,7 +317,7 @@ static int ad5820_probe(struct i2c_client *client,
v4l2_i2c_subdev_init(>subdev, client, _ops);
coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;