diff options
author | paulhsia <paulhsia@chromium.org> | 2021-03-07 23:40:23 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-08 04:15:52 +0000 |
commit | 4e8cef90572d1f2789aee72c2ed7c24fdabc9d9f (patch) | |
tree | b02cc124aa4c8204134bc9b4657d1454a24479b4 | |
parent | 86e1a560610cb3a8dfbf6cedb7984c85830d6855 (diff) | |
download | adhd-4e8cef90572d1f2789aee72c2ed7c24fdabc9d9f.tar.gz |
cras_client: Fix compile-time strncpy errors
strncpy will generate errors like:
error: ‘strncpy’ output may be truncated copying {31, 63} bytes from a string
of length {31, 63}
in compiler.
`strncpy` won't help filling the terminal NULL char in the {32, 64}
position, so it's better to copy with full size and truncate the string
with NULL char explicitly.
BUG=none
TEST=make
Change-Id: Iae5773649ffc55b29f8d6d1c063f0601b7117a1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2739775
Auto-Submit: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Tested-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
-rw-r--r-- | cras/src/libcras/cras_client.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/cras/src/libcras/cras_client.c b/cras/src/libcras/cras_client.c index 4f303bbd..8420db1f 100644 --- a/cras/src/libcras/cras_client.c +++ b/cras/src/libcras/cras_client.c @@ -4212,12 +4212,14 @@ libcras_node_info_create(struct cras_iodev_info *iodev, node->node_->max_supported_channels = iodev->max_supported_channels; node->node_->plugged = ionode->plugged; node->node_->active = ionode->active; - strncpy(node->node_->type, ionode->type, - CRAS_NODE_TYPE_BUFFER_SIZE - 1); + strncpy(node->node_->type, ionode->type, CRAS_NODE_TYPE_BUFFER_SIZE); + node->node_->type[CRAS_NODE_TYPE_BUFFER_SIZE - 1] = '\0'; strncpy(node->node_->node_name, ionode->name, - CRAS_NODE_NAME_BUFFER_SIZE - 1); + CRAS_NODE_NAME_BUFFER_SIZE); + node->node_->node_name[CRAS_NODE_NAME_BUFFER_SIZE - 1] = '\0'; strncpy(node->node_->dev_name, iodev->name, - CRAS_IODEV_NAME_BUFFER_SIZE - 1); + CRAS_IODEV_NAME_BUFFER_SIZE); + node->node_->dev_name[CRAS_IODEV_NAME_BUFFER_SIZE - 1] = '\0'; node->get_id = cras_node_info_get_id; node->get_dev_idx = cras_node_info_get_dev_idx; node->get_node_idx = cras_node_info_get_node_idx; |