Skip to content

Segmentation fault in os_locate #1912

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

Closed
MarcasRealAccount opened this issue Jul 17, 2022 · 1 comment · Fixed by #2449
Closed

Segmentation fault in os_locate #1912

MarcasRealAccount opened this issue Jul 17, 2022 · 1 comment · Fixed by #2449
Labels

Comments

@MarcasRealAccount
Copy link

MarcasRealAccount commented Jul 17, 2022

Slightly Resolved

So I found out it was actually my premake-system.lua script requiring a broken script, but I don't think premake itself should crash like this due to something within the lua scripts.
Therefore the bug in this case would be the os_locate function not checking the arguments before trying to access them.

What seems to be the problem?
Premake crashes with a segmentation fault within os_locate on my macbook.
It would seem like it is either my system or one of the recent commits that caused it, tho I doubt that, cuz it worked previously and then I updated macosx to 12.4 and it started segfaulting.
Anyways the source code is rather dangerous, due to the non existent if (!name) continue;
I am completely aware it is running premake_bootstrap, but the same happens with premake itself

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000100009d7e premake_bootstrap`os_locate(L=0x0000000100808e08) at os_locate.c:40:7
   37  			const char* name = lua_tostring(L, i);
   38
   39  			/* Direct path to an embedded file? */
-> 40  			if (name[0] == '$' && name[1] == '/' && premake_find_embedded_script(name + 2)) {
   41  				lua_pushvalue(L, i);
   42  				return 1;
   43  			}

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000100009d7e premake_bootstrap`os_locate(L=0x0000000100808e08) at os_locate.c:40:7
    frame #1: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103fb00, nresults=-1) at ldo.c:434:11
    frame #2: 0x000000010003edc8 premake_bootstrap`luaV_execute(L=0x0000000100808e08) at lvm.c:1134:13
    frame #3: 0x000000010001c0a2 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103fa80, nResults=-1) at ldo.c:499:5
    frame #4: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103fa80, nResults=-1) at ldo.c:509:3
    frame #5: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=0x0000000000000000) at lapi.c:925:5
    frame #6: 0x000000010000861a premake_bootstrap`chunk_wrapper(L=0x0000000100808e08) at lua_auxlib.c:165:2
    frame #7: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103fa50, nresults=-1) at ldo.c:434:11
    frame #8: 0x000000010001c090 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103fa50, nResults=-1) at ldo.c:498:8
    frame #9: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103fa50, nResults=-1) at ldo.c:509:3
    frame #10: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=(premake_bootstrap`dofilecont at lbaselib.c:356)) at lapi.c:925:5
    frame #11: 0x00000001000133d9 premake_bootstrap`luaB_dofile(L=0x0000000100808e08) at lbaselib.c:367:3
    frame #12: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103fa30, nresults=-1) at ldo.c:434:11
    frame #13: 0x000000010003ee5f premake_bootstrap`luaV_execute(L=0x0000000100808e08) at lvm.c:1149:13
    frame #14: 0x000000010001c0a2 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f990, nResults=-1) at ldo.c:499:5
    frame #15: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f990, nResults=-1) at ldo.c:509:3
    frame #16: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=0x0000000000000000) at lapi.c:925:5
    frame #17: 0x000000010000861a premake_bootstrap`chunk_wrapper(L=0x0000000100808e08) at lua_auxlib.c:165:2
    frame #18: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f960, nresults=-1) at ldo.c:434:11
    frame #19: 0x000000010001c090 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f960, nResults=-1) at ldo.c:498:8
    frame #20: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f960, nResults=-1) at ldo.c:509:3
    frame #21: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=(premake_bootstrap`dofilecont at lbaselib.c:356)) at lapi.c:925:5
    frame #22: 0x00000001000133d9 premake_bootstrap`luaB_dofile(L=0x0000000100808e08) at lbaselib.c:367:3
    frame #23: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f940, nresults=-1) at ldo.c:434:11
    frame #24: 0x000000010003ee5f premake_bootstrap`luaV_execute(L=0x0000000100808e08) at lvm.c:1149:13
    frame #25: 0x000000010001c0a2 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f880, nResults=-1) at ldo.c:499:5
    frame #26: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f880, nResults=-1) at ldo.c:509:3
    frame #27: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=2, nresults=-1, ctx=0, k=0x0000000000000000) at lapi.c:925:5
    frame #28: 0x000000010000861a premake_bootstrap`chunk_wrapper(L=0x0000000100808e08) at lua_auxlib.c:165:2
    frame #29: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f830, nresults=1) at ldo.c:434:11
    frame #30: 0x000000010001c090 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f830, nResults=1) at ldo.c:498:8
    frame #31: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f830, nResults=1) at ldo.c:509:3
    frame #32: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=2, nresults=1, ctx=0, k=0x0000000000000000) at lapi.c:925:5
    frame #33: 0x0000000100027600 premake_bootstrap`ll_require(L=0x0000000100808e08) at loadlib.c:609:3
    frame #34: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f7f0, nresults=-1) at ldo.c:434:11
    frame #35: 0x000000010001c090 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f7f0, nResults=-1) at ldo.c:498:8
    frame #36: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f7f0, nResults=-1) at ldo.c:509:3
    frame #37: 0x000000010001249f premake_bootstrap`f_call(L=0x0000000100808e08, ud=0x00007ff7bfefdb98) at lapi.c:943:3
    frame #38: 0x000000010001afa2 premake_bootstrap`luaD_rawrunprotected(L=0x0000000100808e08, f=(premake_bootstrap`f_call at lapi.c:941), ud=0x00007ff7bfefdb98) at ldo.c:142:3
    frame #39: 0x000000010001c863 premake_bootstrap`luaD_pcall(L=0x0000000100808e08, func=(premake_bootstrap`f_call at lapi.c:941), u=0x00007ff7bfefdb98, old_top=496, ef=0) at ldo.c:729:12
    frame #40: 0x0000000100012354 premake_bootstrap`lua_pcallk(L=0x0000000100808e08, nargs=1, nresults=-1, errfunc=0, ctx=0, k=(premake_bootstrap`finishpcall at lbaselib.c:408)) at lapi.c:969:14
    frame #41: 0x000000010001381a premake_bootstrap`luaB_pcall(L=0x0000000100808e08) at lbaselib.c:424:12
    frame #42: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f7d0, nresults=2) at ldo.c:434:11
    frame #43: 0x000000010003edc8 premake_bootstrap`luaV_execute(L=0x0000000100808e08) at lvm.c:1134:13
    frame #44: 0x000000010001c0a2 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f780, nResults=-1) at ldo.c:499:5
    frame #45: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f780, nResults=-1) at ldo.c:509:3
    frame #46: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=0x0000000000000000) at lapi.c:925:5
    frame #47: 0x000000010000861a premake_bootstrap`chunk_wrapper(L=0x0000000100808e08) at lua_auxlib.c:165:2
    frame #48: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f750, nresults=-1) at ldo.c:434:11
    frame #49: 0x000000010001c090 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f750, nResults=-1) at ldo.c:498:8
    frame #50: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f750, nResults=-1) at ldo.c:509:3
    frame #51: 0x000000010001224f premake_bootstrap`lua_callk(L=0x0000000100808e08, nargs=0, nresults=-1, ctx=0, k=(premake_bootstrap`dofilecont at lbaselib.c:356)) at lapi.c:925:5
    frame #52: 0x00000001000133d9 premake_bootstrap`luaB_dofile(L=0x0000000100808e08) at lbaselib.c:367:3
    frame #53: 0x000000010001bad9 premake_bootstrap`luaD_precall(L=0x0000000100808e08, func=0x000000010103f730, nresults=0) at ldo.c:434:11
    frame #54: 0x000000010003edc8 premake_bootstrap`luaV_execute(L=0x0000000100808e08) at lvm.c:1134:13
    frame #55: 0x000000010001c0a2 premake_bootstrap`luaD_call(L=0x0000000100808e08, func=0x000000010103f630, nResults=1) at ldo.c:499:5
    frame #56: 0x000000010001c169 premake_bootstrap`luaD_callnoyield(L=0x0000000100808e08, func=0x000000010103f630, nResults=1) at ldo.c:509:3
    frame #57: 0x000000010001249f premake_bootstrap`f_call(L=0x0000000100808e08, ud=0x00007ff7bfeff4d8) at lapi.c:943:3
    frame #58: 0x000000010001afa2 premake_bootstrap`luaD_rawrunprotected(L=0x0000000100808e08, f=(premake_bootstrap`f_call at lapi.c:941), ud=0x00007ff7bfeff4d8) at ldo.c:142:3
    frame #59: 0x000000010001c863 premake_bootstrap`luaD_pcall(L=0x0000000100808e08, func=(premake_bootstrap`f_call at lapi.c:941), u=0x00007ff7bfeff4d8, old_top=48, ef=32) at ldo.c:729:12
    frame #60: 0x0000000100012354 premake_bootstrap`lua_pcallk(L=0x0000000100808e08, nargs=0, nresults=1, errfunc=2, ctx=0, k=0x0000000000000000) at lapi.c:969:14
    frame #61: 0x000000010000e051 premake_bootstrap`premake_pcall(L=0x0000000100808e08, nargs=0, nresults=1) at premake.c:287:15
    frame #62: 0x000000010000e1fa premake_bootstrap`premake_execute(L=0x0000000100808e08, argc=2, argv=0x00007ff7bfeff6f0, script="src/_premake_main.lua") at premake.c:316:6
    frame #63: 0x000000010000ebe5 premake_bootstrap`main(argc=2, argv=0x00007ff7bfeff6f0) at premake_main.c:19:7
    frame #64: 0x000000010007551e dyld`start + 462

What did you expect to happen?
It wouldn't crash in that location...

What have you tried so far?
So far I haven't made changes to the source code, as I'm not sure what causes lua_tostring(L, 1) to return a nullptr, tho now reading through the function it seems to do the c equivalent of for _, v in ipairs(premake.path) do end. Edit: I realized too whilst debugging that it reads the function arguments not elements of premake.path.

How can we reproduce this?
Umm, yeah idk.

What version of Premake are you using?
Commit ea2971d

@nickclark2016
Copy link
Member

Can you share the script you had that causes this error? This happens when the lua state pointer is not representing a string or number type.

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

Successfully merging a pull request may close this issue.

2 participants