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

adjust file metatables even in compat53.module mode #67

Merged
merged 2 commits into from
Aug 29, 2024
Merged

Conversation

hishamhm
Copy link
Member

No description provided.

@hishamhm hishamhm reopened this Aug 29, 2024
@hishamhm hishamhm merged commit 7a82c38 into master Aug 29, 2024
30 checks passed
@hishamhm hishamhm deleted the file-write branch August 29, 2024 20:16
@@ -142,7 +142,7 @@ static int l_checkmode (const char *mode) {
typedef luaL_Stream LStream;


#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
#define tolstream(L) (luaL_checktype(L, 1, LUA_TUSERDATA), (LStream *)lua_touserdata(L, 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a security issue: now file methods can be passed an incorrect userdata object and incur C undefined behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into reverting this line because I don't think it ended up being used in practice anyway. We're only really using the io.popen function from this file right now.

I tried using more of this module to implement Lua 5.3-like file:write() behavior in compat53.module mode, but file handles returned by compat-enabled modules would be incompatible with io functions from non-compat-enabled caller code.

In the end, I managed to solve my problem without having to jump this hoop because apparently LuaJIT doesn't such a check, so I can make my modified metatable for files in compat53.module there. As of now, file:write() returns the file handle using compat53.module in all VMs except PUC-Rio Lua 5.1.

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

Successfully merging this pull request may close these issues.

2 participants