From bae522739229e5502b6caacb4adabb69fe85bf29 Mon Sep 17 00:00:00 2001 From: Curtis Malainey Date: Tue, 2 Jan 2024 14:41:05 -0800 Subject: [PATCH] cras: alsa_config: fix string copy We have a buffer limit, use the proper safe function BUG=b:188647460 TEST=build Change-Id: I300f04d720b0b75d6e40101ac1548b9729bffb25 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5160486 Commit-Queue: Li-Yu Yu Reviewed-by: Li-Yu Yu Commit-Queue: Pin-chih Lin Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com Reviewed-by: Pin-chih Lin Auto-Submit: Curtis Malainey Tested-by: Pin-chih Lin --- cras/src/server/BUILD.bazel | 1 + cras/src/server/cras_alsa_config.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cras/src/server/BUILD.bazel b/cras/src/server/BUILD.bazel index e0a892dfb..f6c123fb3 100644 --- a/cras/src/server/BUILD.bazel +++ b/cras/src/server/BUILD.bazel @@ -175,6 +175,7 @@ cc_library( deps = [ "//cras/src/common:blob_wrapper", "//cras/src/common:cras_alsa_card_info", + "//third_party/strlcpy", "//third_party/utlist", "@pkg_config//alsa", ], diff --git a/cras/src/server/cras_alsa_config.c b/cras/src/server/cras_alsa_config.c index 6fdbf3d83..112a237de 100644 --- a/cras/src/server/cras_alsa_config.c +++ b/cras/src/server/cras_alsa_config.c @@ -15,6 +15,7 @@ #include "cras/src/common/blob_wrapper.h" #include "cras/src/server/cras_alsa_card.h" +#include "third_party/strlcpy/strlcpy.h" #include "third_party/utlist/utlist.h" #define MAX_ALSA_CTL_ELEM_NAME_LENGTH 100 @@ -187,7 +188,7 @@ static int ctl_elem_create_for_control_name(const char* name, syslog(LOG_DEBUG, "ctl_elem_create: %s found on card %d", name, card_index); /* Fill the matched keys, i.e. name and matched card index. */ - strcpy((*ctl_elem_p)->name, name); + strlcpy((*ctl_elem_p)->name, name, MAX_ALSA_CTL_ELEM_NAME_LENGTH); (*ctl_elem_p)->card_index = card_index; return 0; }