Fix string copy termination
Test: CTS regression
Bug: 78198288
Change-Id: Id433eb3197d4faf530d5f5090ff95e51689e7088
diff --git a/services/audioflinger/BufLog.cpp b/services/audioflinger/BufLog.cpp
index 2780290..ae96036 100644
--- a/services/audioflinger/BufLog.cpp
+++ b/services/audioflinger/BufLog.cpp
@@ -24,6 +24,7 @@
#include <pthread.h>
#include <stdio.h>
#include <string.h>
+#include <audio_utils/string.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -117,7 +118,7 @@
mByteCount = 0l;
mPaused = false;
if (tag != NULL) {
- strncpy(mTag, tag, BUFLOGSTREAM_MAX_TAGSIZE);
+ (void)audio_utils_strlcpy(mTag, tag);
} else {
mTag[0] = 0;
}
diff --git a/services/audiopolicy/common/managerdefinitions/Android.mk b/services/audiopolicy/common/managerdefinitions/Android.mk
index e263c0c..e69e687 100644
--- a/services/audiopolicy/common/managerdefinitions/Android.mk
+++ b/services/audiopolicy/common/managerdefinitions/Android.mk
@@ -36,6 +36,7 @@
frameworks/av/services/audiopolicy/common/include \
frameworks/av/services/audiopolicy \
frameworks/av/services/audiopolicy/utilities \
+ system/media/audio_utils/include \
ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index 3b1e751..19c2062 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "APM::Devices"
//#define LOG_NDEBUG 0
+#include <audio_utils/string.h>
#include "DeviceDescriptor.h"
#include "TypeConverter.h"
#include "AudioGain.h"
@@ -247,7 +248,7 @@
// ALOG_ASSERT(mModule != NULL);
dstConfig->ext.device.hw_module =
mModule != 0 ? mModule->getHandle() : AUDIO_MODULE_HANDLE_NONE;
- strncpy(dstConfig->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
+ (void)audio_utils_strlcpy_zerofill(dstConfig->ext.device.address, mAddress.string());
}
void DeviceDescriptor::toAudioPort(struct audio_port *port) const
@@ -258,7 +259,7 @@
toAudioPortConfig(&port->active_config);
port->ext.device.type = mDeviceType;
port->ext.device.hw_module = mModule->getHandle();
- strncpy(port->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
+ (void)audio_utils_strlcpy_zerofill(port->ext.device.address, mAddress.string());
}
void DeviceDescriptor::importAudioPort(const sp<AudioPort>& port, bool force) {