aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-02-23 15:46:50 +0100
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-02-23 15:57:01 +0100
commit5ef117b03594402daa6d4e898a835a080c8d7cad (patch)
tree0ff4e5bc529b502004e701163adc813198c1138e
parent7d62ac342b499e3a2d5fd6abccd5f501ffe43b2b (diff)
libdvbv5: dvb-dev-remote: better handle cmd size
Use a define and add a few checks in order to avoid potential mistakes in the future. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--lib/libdvbv5/dvb-dev-remote.c23
-rw-r--r--utils/dvb/dvbv5-daemon.c4
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/libdvbv5/dvb-dev-remote.c b/lib/libdvbv5/dvb-dev-remote.c
index 8935db4d..fdb936a5 100644
--- a/lib/libdvbv5/dvb-dev-remote.c
+++ b/lib/libdvbv5/dvb-dev-remote.c
@@ -79,9 +79,10 @@ struct ringbuffer {
pthread_mutex_t lock;
};
+#define CMD_SIZE 80
struct queued_msg {
int seq;
- char cmd[80];
+ char cmd[CMD_SIZE];
int retval;
pthread_mutex_t lock;
@@ -113,6 +114,16 @@ struct dvb_dev_remote_priv {
void *user_priv;
};
+char *my_strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *rc;
+
+ rc = strncpy(dst, src, siz);
+ dst[siz - 1] = '\0';
+
+ return rc;
+}
+
void stack_dump(struct dvb_v5_fe_parms_priv *parms)
{
#ifdef HAVE_BACKTRACE
@@ -217,11 +228,11 @@ static ssize_t prepare_data(struct dvb_v5_fe_parms_priv *parms,
}
static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
- const char *cmd, const char *fmt, ...)
+ const char cmd[CMD_SIZE], const char *fmt, ...)
__attribute__ (( format( printf, 4, 5 )));
static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
- const char *cmd, const char *fmt, ...)
+ const char cmd[CMD_SIZE], const char *fmt, ...)
{
struct dvb_v5_fe_parms_priv *parms = (void *)dvb->d.fe_parms;
struct dvb_dev_remote_priv *priv = dvb->priv;
@@ -240,7 +251,7 @@ static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
pthread_mutex_init(&msg->lock, NULL);
pthread_cond_init(&msg->cond, NULL);
- strcpy(msg->cmd, cmd);
+ my_strlcpy(msg->cmd, cmd, sizeof(*msg->cmd));
pthread_mutex_lock(&priv->lock_io);
msg->seq = ++priv->seq;
@@ -317,7 +328,7 @@ static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
}
static struct queued_msg *send_buf(struct dvb_device_priv *dvb, int fd,
- const char *cmd,
+ const char cmd[CMD_SIZE],
const char *in_buf, const size_t in_size)
{
struct dvb_v5_fe_parms_priv *parms = (void *)dvb->d.fe_parms;
@@ -336,7 +347,7 @@ static struct queued_msg *send_buf(struct dvb_device_priv *dvb, int fd,
pthread_mutex_init(&msg->lock, NULL);
pthread_cond_init(&msg->cond, NULL);
- strcpy(msg->cmd, cmd);
+ my_strlcpy(msg->cmd, cmd, sizeof(*msg->cmd));
pthread_mutex_lock(&priv->lock_io);
msg->seq = ++priv->seq;
diff --git a/utils/dvb/dvbv5-daemon.c b/utils/dvb/dvbv5-daemon.c
index 5a46046a..43b5c777 100644
--- a/utils/dvb/dvbv5-daemon.c
+++ b/utils/dvb/dvbv5-daemon.c
@@ -79,6 +79,8 @@
const char *argp_program_version = PROGRAM_NAME " version " V4L_UTILS_VERSION;
const char *argp_program_bug_address = "Mauro Carvalho Chehab <mchehab@kernel.org>";
+#define CMD_SIZE 80
+
static const char doc[] = N_(
"\nA DVB remote daemon using API version 5\n");
@@ -1341,7 +1343,7 @@ static void *start_server(void *fd_pointer)
{
const struct method_types *method;
int fd = *(int *)fd_pointer, ret, flag = 1;
- char buf[REMOTE_BUF_SIZE + 8], cmd[80], *p;
+ char buf[REMOTE_BUF_SIZE + 8], cmd[CMD_SIZE], *p;
ssize_t size;
uint32_t seq;
int bufsize;

Privacy Policy