Use strtok_r()/strtok_s() instead of regular strtok()
This commit is contained in:
parent
2bb026c763
commit
91b4186b8a
3 changed files with 15 additions and 7 deletions
|
|
@ -52,6 +52,12 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LC_WINDOWS
|
||||||
|
// Windows doesn't have strtok_r() but it has the same
|
||||||
|
// function named strtok_s().
|
||||||
|
#define strtok_r strtok_s
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "Limelight.h"
|
#include "Limelight.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -972,6 +972,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
|
||||||
char* sessionId;
|
char* sessionId;
|
||||||
char* pingPayload;
|
char* pingPayload;
|
||||||
int error = -1;
|
int error = -1;
|
||||||
|
char* strtokCtx;
|
||||||
|
|
||||||
if (!setupStream(&response,
|
if (!setupStream(&response,
|
||||||
AppVersionQuad[0] >= 5 ? "streamid=audio/0/0" : "streamid=audio",
|
AppVersionQuad[0] >= 5 ? "streamid=audio/0/0" : "streamid=audio",
|
||||||
|
|
@ -1025,7 +1026,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
|
||||||
// resolves any 454 session not found errors on
|
// resolves any 454 session not found errors on
|
||||||
// standard RTSP server implementations.
|
// standard RTSP server implementations.
|
||||||
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
|
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
|
||||||
sessionIdString = strdup(strtok(sessionId, ";"));
|
sessionIdString = strdup(strtok_r(sessionId, ";", &strtokCtx));
|
||||||
if (sessionIdString == NULL) {
|
if (sessionIdString == NULL) {
|
||||||
Limelog("Failed to duplicate session ID string\n");
|
Limelog("Failed to duplicate session ID string\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
char flag;
|
char flag;
|
||||||
bool messageEnded = false;
|
bool messageEnded = false;
|
||||||
|
|
||||||
|
char* strtokCtx = NULL;
|
||||||
char* payload = NULL;
|
char* payload = NULL;
|
||||||
char* opt = NULL;
|
char* opt = NULL;
|
||||||
int statusCode = 0;
|
int statusCode = 0;
|
||||||
|
|
@ -89,7 +90,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
messageBuffer[length] = 0;
|
messageBuffer[length] = 0;
|
||||||
|
|
||||||
// Get the first token of the message
|
// Get the first token of the message
|
||||||
token = strtok(messageBuffer, delim);
|
token = strtok_r(messageBuffer, delim, &strtokCtx);
|
||||||
if (token == NULL) {
|
if (token == NULL) {
|
||||||
exitCode = RTSP_ERROR_MALFORMED;
|
exitCode = RTSP_ERROR_MALFORMED;
|
||||||
goto ExitFailure;
|
goto ExitFailure;
|
||||||
|
|
@ -102,7 +103,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
protocol = token;
|
protocol = token;
|
||||||
|
|
||||||
// Get the status code
|
// Get the status code
|
||||||
token = strtok(NULL, delim);
|
token = strtok_r(NULL, delim, &strtokCtx);
|
||||||
statusCode = atoi(token);
|
statusCode = atoi(token);
|
||||||
if (token == NULL) {
|
if (token == NULL) {
|
||||||
exitCode = RTSP_ERROR_MALFORMED;
|
exitCode = RTSP_ERROR_MALFORMED;
|
||||||
|
|
@ -110,7 +111,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the status string
|
// Get the status string
|
||||||
statusStr = strtok(NULL, end);
|
statusStr = strtok_r(NULL, end, &strtokCtx);
|
||||||
if (statusStr == NULL) {
|
if (statusStr == NULL) {
|
||||||
exitCode = RTSP_ERROR_MALFORMED;
|
exitCode = RTSP_ERROR_MALFORMED;
|
||||||
goto ExitFailure;
|
goto ExitFailure;
|
||||||
|
|
@ -125,12 +126,12 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
else {
|
else {
|
||||||
flag = TYPE_REQUEST;
|
flag = TYPE_REQUEST;
|
||||||
command = token;
|
command = token;
|
||||||
target = strtok(NULL, delim);
|
target = strtok_r(NULL, delim, &strtokCtx);
|
||||||
if (target == NULL) {
|
if (target == NULL) {
|
||||||
exitCode = RTSP_ERROR_MALFORMED;
|
exitCode = RTSP_ERROR_MALFORMED;
|
||||||
goto ExitFailure;
|
goto ExitFailure;
|
||||||
}
|
}
|
||||||
protocol = strtok(NULL, delim);
|
protocol = strtok_r(NULL, delim, &strtokCtx);
|
||||||
if (protocol == NULL) {
|
if (protocol == NULL) {
|
||||||
exitCode = RTSP_ERROR_MALFORMED;
|
exitCode = RTSP_ERROR_MALFORMED;
|
||||||
goto ExitFailure;
|
goto ExitFailure;
|
||||||
|
|
@ -145,7 +146,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||||
// Parse remaining options
|
// Parse remaining options
|
||||||
while (token != NULL)
|
while (token != NULL)
|
||||||
{
|
{
|
||||||
token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end);
|
token = strtok_r(NULL, typeFlag == TOKEN_OPTION ? optDelim : end, &strtokCtx);
|
||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
if (typeFlag == TOKEN_OPTION) {
|
if (typeFlag == TOKEN_OPTION) {
|
||||||
opt = token;
|
opt = token;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue