Skip to content

Commit

Permalink
Bugs fix
Browse files Browse the repository at this point in the history
Fix wrong type of alterId in Clash VMess nodes (#325).
Fix broken parsing of ShadowsocksR subscription.
Fix possible crash when running scripts.
  • Loading branch information
tindy2013 committed Mar 24, 2021
1 parent b42bfec commit fe20b2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const string_
case ProxyType::VMess:
singleproxy["type"] = "vmess";
singleproxy["uuid"] = x.UserId;
singleproxy["alterId"] = x.AlterId;
singleproxy["alterId"] = static_cast<uint32_t>(x.AlterId);
singleproxy["cipher"] = x.EncryptMethod;
singleproxy["tls"] = x.TLSSecure;
if(!scv.is_undef())
Expand Down
9 changes: 3 additions & 6 deletions src/handler/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,15 +1526,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
lExcludeRemarks = string_array{argExcludeRemark};

/// initialize script runtime
if(authorized)
if(authorized && !gScriptCleanContext)
{
ext.js_runtime = new qjs::Runtime();
script_runtime_init(*ext.js_runtime);
if(!gScriptCleanContext)
{
ext.js_context = new qjs::Context(*ext.js_runtime);
script_context_init(*ext.js_context);
}
ext.js_context = new qjs::Context(*ext.js_runtime);
script_context_init(*ext.js_context);
}

//start parsing urls
Expand Down
2 changes: 1 addition & 1 deletion src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void explodeSSR(std::string ssr, Proxy &node)
}
else
{
ssrConstruct(node, group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam);
ssrConstruct(node, group, remarks, server, port, protocol, method, obfs, password, obfsparam, protoparam);
}
}

Expand Down
33 changes: 15 additions & 18 deletions src/script/script_quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace qjs
JS_SetPropertyStr(ctx, obj, "ProxyInfo", JS_NewStringLen(ctx, n.proxyStr.c_str(), n.proxyStr.size()));
*/
JS_SetPropertyStr(ctx, obj, "Type", JS_NewInt32(ctx, n.Type));
JS_SetPropertyStr(ctx, obj, "ID", JS_NewInt32(ctx, n.Id));
JS_SetPropertyStr(ctx, obj, "GroupID", JS_NewInt32(ctx, n.GroupId));
JS_SetPropertyStr(ctx, obj, "Id", JS_NewInt32(ctx, n.Id));
JS_SetPropertyStr(ctx, obj, "GroupId", JS_NewInt32(ctx, n.GroupId));
JS_SetPropertyStr(ctx, obj, "Group", JS_NewStringLen(ctx, n.Group.c_str(), n.Group.size()));
JS_SetPropertyStr(ctx, obj, "Remark", JS_NewStringLen(ctx, n.Remark.c_str(), n.Remark.size()));
JS_SetPropertyStr(ctx, obj, "Server", JS_NewStringLen(ctx, n.Hostname.c_str(), n.Hostname.size()));
Expand Down Expand Up @@ -150,8 +150,9 @@ namespace qjs
node.port = JS_GetPropertyToInt32(ctx, v, "Port");
node.proxyStr = JS_GetPropertyToString(ctx, v, "ProxyInfo");
*/
node.Id = JS_GetPropertyToUInt32(ctx, v, "Id");
node.GroupId = JS_GetPropertyToUInt32(ctx, v, "GroupId");
node.Type = JS_GetPropertyToInt32(ctx, v, "Type");
node.Id = JS_GetPropertyToInt32(ctx, v, "Id");
node.GroupId = JS_GetPropertyToInt32(ctx, v, "GroupId");
node.Group = JS_GetPropertyToString(ctx, v, "Group");
node.Remark = JS_GetPropertyToString(ctx, v, "Remark");
node.Hostname = JS_GetPropertyToString(ctx, v, "Hostname");
Expand Down Expand Up @@ -192,22 +193,18 @@ namespace qjs
template <typename Fn>
void script_safe_runner(qjs::Runtime *runtime, qjs::Context *context, Fn runnable, bool clean_context = false)
{
if(runtime != nullptr)
qjs::Runtime *internal_runtime = runtime;
qjs::Context *internal_context = context;
defer(if(clean_context) {delete internal_context; delete internal_runtime;} )
if(clean_context)
{
qjs::Context *internal_context = context;
bool use_internal = false;
defer(if(use_internal && internal_context) delete internal_context;)
if(clean_context)
{
internal_context = new qjs::Context(*runtime);
use_internal = true;
script_context_init(*internal_context);
}
if(internal_context != nullptr)
runnable(*internal_context);
if(clean_context)
delete internal_context;
internal_runtime = new qjs::Runtime();
script_runtime_init(*internal_runtime);
internal_context = new qjs::Context(*internal_runtime);
script_context_init(*internal_context);
}
if(internal_runtime && internal_context)
runnable(*internal_context);
}

#endif // SCRIPT_QUICKJS_H_INCLUDED

0 comments on commit fe20b2d

Please sign in to comment.