-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for SRTO_STREAMID #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,15 @@ Napi::Value NodeSRT::SetSockOpt(const Napi::CallbackInfo& info) { | |
Napi::Error::New(env, srt_getlasterror_str()).ThrowAsJavaScriptException(); | ||
return Napi::Number::New(env, SRT_ERROR); | ||
} | ||
} else if (info[2].IsString()) { | ||
Napi::String value = info[2].As<Napi::String>(); | ||
int32_t optName = option; | ||
const char * optValue = std::string(value).c_str(); | ||
result = srt_setsockflag(socketValue, (SRT_SOCKOPT)optName, optValue, sizeof(string)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just adding here also, this does "somehow" work as long as your string data passed is smaller than whatever probably somewhat contributing to it having worked at all is that C-string is null-terminated, so even if libSRT copies this into a too large buffer along with some garbage, it reads the string properly ... but still this could crash as potentially letting srt_setsockflag read/copy from random place in memory itfp -- just in case this ever crashed for you; that is probably why. |
||
if (result == SRT_ERROR) { | ||
Napi::Error::New(env, srt_getlasterror_str()).ThrowAsJavaScriptException(); | ||
return Napi::Number::New(env, SRT_ERROR); | ||
} | ||
} | ||
return Napi::Number::New(env, result); | ||
} | ||
|
@@ -344,10 +353,12 @@ Napi::Value NodeSRT::GetSockOpt(const Napi::CallbackInfo& info) { | |
} | ||
case SRTO_PACKETFILTER: | ||
case SRTO_PASSPHRASE: | ||
case SRTO_STREAMID: | ||
{ | ||
char optValue[512]; | ||
int optSize = sizeof(optValue); | ||
result = srt_getsockflag(socketValue, (SRT_SOCKOPT)optName, (void *)&optValue, &optSize); | ||
|
||
returnVal = Napi::Value::From(env, std::string(optValue)); | ||
break; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang compiler spits out a warning here for understandable reasons.
that std::string objects may be kicked off the stack just after c_str returns.
meaning that the mem at the pointer is freed then, and potentially the value passed not ensured to be what you expect here at all (even if this may work, you actually pass a pointer to already deallocated mem here every time).