2
0
Эх сурвалжийг харах

Added consistent checks on size parameter

Paul-Louis Ageneau 5 жил өмнө
parent
commit
b4f7c506da
1 өөрчлөгдсөн 14 нэмэгдсэн , 9 устгасан
  1. 14 9
      src/rtc.cpp

+ 14 - 9
src/rtc.cpp

@@ -333,6 +333,9 @@ int rtcGetLocalAddress(int pc, char *buffer, int size) {
 		if (!buffer)
 			throw std::invalid_argument("Unexpected null pointer");
 
+		if (size <= 0)
+			return 0;
+
 		if (auto addr = peerConnection->localAddress()) {
 			const char *data = addr->data();
 			size = std::min(size_t(size - 1), addr->size());
@@ -350,6 +353,9 @@ int rtcGetRemoteAddress(int pc, char *buffer, int size) {
 		if (!buffer)
 			throw std::invalid_argument("Unexpected null pointer");
 
+		if (size <= 0)
+			return 0;
+
 		if (auto addr = peerConnection->remoteAddress()) {
 			const char *data = addr->data();
 			size = std::min(size_t(size - 1), addr->size());
@@ -367,16 +373,15 @@ int rtcGetDataChannelLabel(int dc, char *buffer, int size) {
 		if (!buffer)
 			throw std::invalid_argument("Unexpected null pointer");
 
-		if (size >= 0) {
-			string label = dataChannel->label();
-			const char *data = label.data();
-			size = std::min(size_t(size - 1), label.size());
-			std::copy(data, data + size, buffer);
-			buffer[size] = '\0';
-			return size + 1;
-		} else {
+		if (size <= 0)
 			return 0;
-		}
+
+		string label = dataChannel->label();
+		const char *data = label.data();
+		size = std::min(size_t(size - 1), label.size());
+		std::copy(data, data + size, buffer);
+		buffer[size] = '\0';
+		return size + 1;
 	});
 }