Skip to content

RFunction params with an embedded NUL longjmp past C++ RPC handlers #19697

Description

@kevinushey

#19683 refuses embedded NULs in JSON-RPC params before calling R-implemented handlers (callRHandler() in RJsonRpc.cpp). C++ handlers that pass a client string to RFunction::addParam() have the same exposure. json::Value::getString() keeps the NUL, and sexp::create(const std::string&) builds the string with Rf_mkCharLenCE. R then raises embedded nul in string while the arguments are built, outside the protected call, so the error longjmps past the handler and the RPC is never answered. Example: getRmdPublishDetails() in SessionRSConnect.cpp, with a NUL in target.

Related: create(const std::string&) raises an error on a NUL, while the std::vector / std::set / map overloads and JSON object member names go through mkCharUtf8() -> Rf_mkCharCE(), which silently cuts the string off at the NUL.

Proposed direction: scan string-bearing params and names in RFunction::addParam(), record the first problem and return it from call(), and build every string create() overload on one mkChar helper. The callRHandler() check then moves there. Wrapping each create() in executeSafely() is the generic alternative, but it runs R_ToplevelExec and swaps R's error handler on every parameter, on a hot path.

Raised in review of #19683: #19683 (comment)

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions