Skip to content

Commit

Permalink
fix: report an error when trying to release unknown ports
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkpunkd committed May 14, 2019
1 parent 5ef8f73 commit d1c4171
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cxx/orbital.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ napi_value getPlayPortStatus(napi_env env, napi_callback_info info) {
portNames = server->getPortNames();
bool foundPort = false;
for ( int x = 0 ; x < portNames->length() ; x++ ) {
if (wcscmp(wportName.data(), (const wchar_t *) portNames[x])) {
if (wcscmp(wportName.data(), (const wchar_t *) portNames[x]) == 0) {
foundPort = true;
break;
}
Expand Down Expand Up @@ -564,6 +564,7 @@ napi_value releasePort(napi_env env, napi_callback_info info) {
int32_t serverID;
char* portName;
size_t portNameLen;
Quentin::WStrings_var portNames;

try {
status = retrieveZonePortal(env, info, &orb, &zp);
Expand Down Expand Up @@ -602,6 +603,23 @@ napi_value releasePort(napi_env env, napi_callback_info info) {
Quentin::Server_ptr server = zp->getServer(serverID);

std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
std::wstring wportName = utf8_conv.from_bytes(portName);

// Prevent accidental creation of extra port
portNames = server->getPortNames();
bool foundPort = false;
for ( int x = 0 ; x < portNames->length() ; x++ ) {
if (wcscmp(wportName.data(), (const wchar_t *) portNames[x]) == 0) {
foundPort = true;
break;
}
}
free(portName);
printf("Found port is %i\n", foundPort);
if (!foundPort) {
NAPI_THROW_ORB_DESTROY("Cannot release a port with an unknown port name.");
}

Quentin::Port_ptr port = server->getPort(utf8_conv.from_bytes(portName).data(), 0);

port->reset();
Expand Down

0 comments on commit d1c4171

Please sign in to comment.