From cdfdbb45500124be7a9e98801ac79828393aedd3 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 20 Dec 2021 15:51:49 -0800 Subject: [PATCH] build: Fix build when sanitizer are enabled This fixes various issues found when sanitizers are enabled. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- monitor/packet.c | 3 ++- peripheral/main.c | 2 +- profiles/audio/a2dp.c | 5 ++++- profiles/audio/avctp.c | 2 +- profiles/network/bnep.c | 4 ++-- src/shared/gatt-server.c | 2 -- tools/mesh-gatt/util.c | 11 ++++++++--- tools/test-runner.c | 2 +- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index 04a4b2f7..1cafadd9 100755 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -329,7 +329,8 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, if ((filter_mask & PACKET_FILTER_SHOW_INDEX) && index != HCI_DEV_NONE) { if (use_color()) { - n = sprintf(ts_str + ts_pos, "%s", COLOR_INDEX_LABEL); + n = snprintf(ts_str + ts_pos, sizeof(ts_str) - ts_pos, + "%s", COLOR_INDEX_LABEL); if (n > 0) ts_pos += n; } diff --git a/peripheral/main.c b/peripheral/main.c index b20006e2..b4063d68 100755 --- a/peripheral/main.c +++ b/peripheral/main.c @@ -72,7 +72,7 @@ static void prepare_filesystem(void) if (!is_init) return; - for (i = 0; mount_table[i].fstype; i++) { + for (i = 0; mount_table[i].fstype && mount_table[i].target; i++) { struct stat st; if (lstat(mount_table[i].target, &st) < 0) { diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index 2c2e0c2e..4cd4ddec 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -1415,9 +1415,12 @@ static gboolean a2dp_reconfigure(gpointer data) if (setup->rsep) { cap = avdtp_get_codec(setup->rsep->sep); rsep_codec = (struct avdtp_media_codec_capability *) cap->data; + /* Check that codec really match after closing */ + if (sep->codec != rsep_codec->media_codec_type) + setup->rsep = NULL; } - if (!setup->rsep || sep->codec != rsep_codec->media_codec_type) + if (!setup->rsep) setup->rsep = find_remote_sep(setup->chan, sep); if (!setup->rsep) { diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c index fc43e95c..e51485bb 100644 --- a/profiles/audio/avctp.c +++ b/profiles/audio/avctp.c @@ -1239,7 +1239,7 @@ static int uinput_create(struct btd_device *device, const char *name, memset(&dev, 0, sizeof(dev)); if (name) { - strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE); + strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE - 1); dev.name[UINPUT_MAX_NAME_SIZE - 1] = '\0'; } diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c index 5a83fc86..da71d6a5 100755 --- a/profiles/network/bnep.c +++ b/profiles/network/bnep.c @@ -143,7 +143,7 @@ static int bnep_connadd(int sk, uint16_t role, char *dev) struct bnep_connadd_req req; memset(&req, 0, sizeof(req)); - strncpy(req.device, dev, 16); + strncpy(req.device, dev, 15); req.device[15] = '\0'; req.sock = sk; @@ -385,7 +385,7 @@ struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role, session->io = g_io_channel_unix_new(dup_fd); session->src = local_role; session->dst = remote_role; - strncpy(session->iface, iface, 16); + strncpy(session->iface, iface, 15); session->iface[15] = '\0'; g_io_channel_set_close_on_unref(session->io, TRUE); diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c index 0135b5c3..dd7b0011 100644 --- a/src/shared/gatt-server.c +++ b/src/shared/gatt-server.c @@ -1145,8 +1145,6 @@ static void read_multiple_cb(struct bt_att_chan *chan, uint8_t opcode, } data = read_mult_data_new(server, chan, opcode, length / 2); - if (!data) - goto error; for (i = 0; i < data->num_handles; i++) data->handles[i] = get_le16(pdu + i * 2); diff --git a/tools/mesh-gatt/util.c b/tools/mesh-gatt/util.c index e845c411..eb8b8eb2 100644 --- a/tools/mesh-gatt/util.c +++ b/tools/mesh-gatt/util.c @@ -41,9 +41,14 @@ void print_byte_array(const char *prefix, const void *ptr, int len) char *line, *bytes; int i; - line = g_malloc(strlen(prefix) + (16 * 3) + 2); - sprintf(line, "%s ", prefix); - bytes = line + strlen(prefix) + 1; + if (prefix) { + line = g_malloc(strlen(prefix) + (16 * 3) + 2); + sprintf(line, "%s ", prefix); + bytes = line + strlen(prefix) + 1; + } else { + line = g_malloc((16 * 3) + 2); + bytes = line + 1; + } for (i = 0; i < len; ++i) { sprintf(bytes, "%2.2x ", data[i]); diff --git a/tools/test-runner.c b/tools/test-runner.c index 45b66df8..80d91040 100755 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -135,7 +135,7 @@ static void prepare_sandbox(void) { int i; - for (i = 0; mount_table[i].fstype; i++) { + for (i = 0; mount_table[i].fstype && mount_table[i].target; i++) { struct stat st; if (lstat(mount_table[i].target, &st) < 0) { -- 2.34.1