[Live-devel] [patch] make sure string storage has enough room for the null char
Erik Hovland
erik at hovland.org
Tue Jul 8 09:09:24 PDT 2008
This patch is the one I am least comfortable with. I have no idea if the
strings that are being created require a null char to terminate them.
But to stimulate discussion I am posting the patches that do make sure
there is room for the null char in a few strings where it seems it was
no accounted for. Please let me know if I got this one wrong. I am happy
to drop this patch.
E
---
liveMedia/RTSPClient.cpp | 4 ++--
liveMedia/ServerMediaSession.cpp | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/liveMedia/RTSPClient.cpp b/liveMedia/RTSPClient.cpp
index 3d9eab1..b5bde5d 100644
--- a/liveMedia/RTSPClient.cpp
+++ b/liveMedia/RTSPClient.cpp
@@ -100,7 +100,7 @@ void RTSPClient::setUserAgentString(char const* userAgentStr) {
// Change the existing user agent header string:
char const* const formatStr = "User-Agent: %s\r\n";
- unsigned headerSize = strlen(formatStr) + strlen(userAgentStr);
+ unsigned headerSize = strlen(formatStr) + strlen(userAgentStr) + 1;
delete[] fUserAgentHeaderStr;
fUserAgentHeaderStr = new char[headerSize];
sprintf(fUserAgentHeaderStr, formatStr, userAgentStr);
@@ -1979,7 +1979,7 @@ RTSPClient::createAuthenticatorString(Authenticator const* authenticator,
sprintf(usernamePassword, "%s:%s", authenticator->username(), authenticator->password());
char* response = base64Encode(usernamePassword, usernamePasswordLength);
- unsigned authBufSize = strlen(authFmt) + strlen(response);
+ unsigned authBufSize = strlen(authFmt) + strlen(response) + 1;
authenticatorStr = new char[authBufSize];
sprintf(authenticatorStr, authFmt, response);
delete[] response; delete[] usernamePassword;
diff --git a/liveMedia/ServerMediaSession.cpp b/liveMedia/ServerMediaSession.cpp
index be1efc7..cfe9ef3 100644
--- a/liveMedia/ServerMediaSession.cpp
+++ b/liveMedia/ServerMediaSession.cpp
@@ -195,7 +195,7 @@ char* ServerMediaSession::generateSDPDescription() {
"a=source-filter: incl IN IP4 * %s\r\n"
"a=rtcp-unicast: reflection\r\n";
unsigned sourceFilterFmtSize = strlen(sourceFilterFmt)
- + ipAddressStrSize;
+ + ipAddressStrSize + 1;
sourceFilterLine = new char[sourceFilterFmtSize];
sprintf(sourceFilterLine, sourceFilterFmt,
--
Erik Hovland
mail: erik at hovland.org
web: http://hovland.org/
PGP/GPG public key available on request
More information about the live-devel
mailing list