Skip to content
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

Fix usage of wrong string type in os.execute #191

Merged
merged 1 commit into from
Apr 10, 2021

Conversation

PRTTMPRPHT
Copy link
Contributor

Hello there,

I noticed that os.execute is currently broken (tested with node v15.0.1).
The string fed into the implementation is actually a lua string (passed as an Uint8Array).
This needs to be converted to a normal JS string, as otherwise, exec will reject the input with the following error message:

The "file" argument must be of type string. Received an instance of Uint8Array

Here is a quick&dirty sample script to test this:

const {lauxlib, lua, lualib, to_jsstring, to_luastring} = require("fengari");

let L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);

const luaSource = to_luastring("return os.execute('hostname')");

const exitCode = lauxlib.luaL_dostring(L, luaSource);

if (exitCode !== 0) {
    const errorMessage = lua.lua_tostring(L, -1);
    console.log("Error:", to_jsstring(errorMessage));
    return;
}

console.log(to_jsstring(lua.lua_tostring(L, -1)));

With the proposed fix, it will output the hostname correctly.

@sonarcloud
Copy link

sonarcloud bot commented Apr 9, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell E 8 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@daurnimator daurnimator merged commit dfdd629 into fengari-lua:master Apr 10, 2021
@daurnimator
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants