Skip to content

Fix potential createStopWatch when given nil crash#3272

Merged
vadi2 merged 2 commits intoMudlet:release-4.4from
vadi2:fix-createstopwatch-crash
Dec 14, 2019
Merged

Fix potential createStopWatch when given nil crash#3272
vadi2 merged 2 commits intoMudlet:release-4.4from
vadi2:fix-createstopwatch-crash

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Dec 12, 2019

Brief overview of PR changes/additions

Fix createStopWatch crash because not all variables were passed to the printf-like function.

Motivation for adding to Mudlet

Mudlet should never crash!

Other info (issues closed, discussion etc)

Also "name as string or autostart as boolean are optional, got nil!" sounds pretty confusing to me, so I've edited out the optional part, like with other messages. If it's optional, then don't complain that you got nil...

Also "name as string or autostart as boolean are optional, got nil!" sounds pretty confusing to me, so I've edited out the optional part, like with other messages. If it's optional, then don't complain that you got nil...
@vadi2 vadi2 added this to the 4.4.0 milestone Dec 12, 2019
@vadi2 vadi2 requested a review from SlySven December 12, 2019 02:04
@vadi2 vadi2 requested a review from a team as a code owner December 12, 2019 02:04
@vadi2 vadi2 requested review from a team December 12, 2019 02:04
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Dec 12, 2019

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@vadi2 vadi2 changed the title Fix createStopWatch crash Fix potential createStopWatch when given nil crash Dec 12, 2019
Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

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

Also "name as string or autostart as boolean are optional, got nil!" sounds pretty confusing to me, so I've edited out the optional part, like with other messages. If it's optional, then don't complain that you got nil...

If the only argument provided to a function is a nil then I believed Lua would collapse / discard that argument - so then n would become zero and that extra test would never be reached - or have I got that rong?

I agree that missing an argument specified in the printf format string to the lua_pushfstring(...) error messages is a bug and needs fixing...

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Dec 13, 2019

have I got that rong?

Yes, that is not the case for the C API - it differentiates between 'nill' and 'none'. It's the Lua side of the API that will discard it.

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

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

Can you document in the comment that the C API doesn't ignore a nil explicitly passed as an argument - I wasn't aware of that behaviour (c.f. the Lua side that does for trailing arguments of that type) and will need to watch for that in other cases where we (I) check for the argument type with a lua_type(lua_State*, int) call...

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Dec 14, 2019

Sure thing!

@vadi2 vadi2 merged commit 5da9570 into Mudlet:release-4.4 Dec 14, 2019
@vadi2 vadi2 deleted the fix-createstopwatch-crash branch December 14, 2019 14:19
vadi2 added a commit that referenced this pull request Mar 10, 2020
* Fix createStopWatch(nil) potentially crashing Mudlet

Also "name as string or autostart as boolean are optional, got nil!" sounds pretty confusing to me, so I've edited out the optional part, like with other messages. If it's optional, then don't complain that you got nil...

* Add note per review
// note that 'nil' will still count towards the stack's gettop amount
} else {
lua_pushfstring(L, "createStopWatch: bad argument #%d type (name as string or autostart as boolean are optional, got %s!)", luaL_typename(L, s));
lua_pushfstring(L, "createStopWatch: bad argument #%d type (name as string or autostart as boolean are optional, got %s!)", s, luaL_typename(L, s));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ouch! 🌳 🥄 award for me there and below for not providing that int...

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.

3 participants