Fixes off-by-one error in video capture module

Fixed: webrtc:11290
Change-Id: I471b409c27d6ee577a0ed84e3a09d31fbbc16fcd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/222609
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34333}
This commit is contained in:
Johannes Kron 2021-06-17 10:37:22 +02:00 committed by WebRTC LUCI CQ
parent bad0ab0858
commit 7c719b0db1
3 changed files with 7 additions and 7 deletions

View File

@ -116,7 +116,7 @@ int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber,
memset(deviceNameUTF8, 0, deviceNameLength);
memcpy(cameraName, cap.card, sizeof(cap.card));
if (deviceNameLength >= strlen(cameraName)) {
if (deviceNameLength > strlen(cameraName)) {
memcpy(deviceNameUTF8, cameraName, strlen(cameraName));
} else {
RTC_LOG(LS_INFO) << "buffer passed is too small";
@ -126,7 +126,7 @@ int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber,
if (cap.bus_info[0] != 0) // may not available in all drivers
{
// copy device id
if (deviceUniqueIdUTF8Length >= strlen((const char*)cap.bus_info)) {
if (deviceUniqueIdUTF8Length > strlen((const char*)cap.bus_info)) {
memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length);
memcpy(deviceUniqueIdUTF8, cap.bus_info,
strlen((const char*)cap.bus_info));
@ -146,7 +146,7 @@ int32_t DeviceInfoLinux::CreateCapabilityMap(const char* deviceUniqueIdUTF8) {
const int32_t deviceUniqueIdUTF8Length =
(int32_t)strlen((char*)deviceUniqueIdUTF8);
if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) {
if (deviceUniqueIdUTF8Length >= kVideoCaptureUniqueNameLength) {
RTC_LOG(LS_INFO) << "Device name too long";
return -1;
}

View File

@ -213,7 +213,7 @@ IBaseFilter* DeviceInfoDS::GetDeviceFilter(const char* deviceUniqueIdUTF8,
uint32_t productUniqueIdUTF8Length) {
const int32_t deviceUniqueIdUTF8Length = (int32_t)strlen(
(char*)deviceUniqueIdUTF8); // UTF8 is also NULL terminated
if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) {
if (deviceUniqueIdUTF8Length >= kVideoCaptureUniqueNameLength) {
RTC_LOG(LS_INFO) << "Device name too long";
return NULL;
}
@ -306,7 +306,7 @@ int32_t DeviceInfoDS::CreateCapabilityMap(const char* deviceUniqueIdUTF8)
const int32_t deviceUniqueIdUTF8Length =
(int32_t)strlen((char*)deviceUniqueIdUTF8);
if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) {
if (deviceUniqueIdUTF8Length >= kVideoCaptureUniqueNameLength) {
RTC_LOG(LS_INFO) << "Device name too long";
return -1;
}
@ -568,7 +568,7 @@ void DeviceInfoDS::GetProductId(const char* devicePath,
// Find the second occurrence.
pos = strchr(pos + 1, '&');
uint32_t bytesToCopy = (uint32_t)(pos - startPos);
if (pos && (bytesToCopy <= productUniqueIdUTF8Length) &&
if (pos && (bytesToCopy < productUniqueIdUTF8Length) &&
bytesToCopy <= kVideoCaptureProductIdLength) {
strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Length,
(char*)startPos, bytesToCopy);

View File

@ -57,7 +57,7 @@ VideoCaptureDS::~VideoCaptureDS() {
int32_t VideoCaptureDS::Init(const char* deviceUniqueIdUTF8) {
const int32_t nameLength = (int32_t)strlen((char*)deviceUniqueIdUTF8);
if (nameLength > kVideoCaptureUniqueNameLength)
if (nameLength >= kVideoCaptureUniqueNameLength)
return -1;
// Store the device name