Welcome to the Builder Academy

Question Problems with looking at 2.mob/object.

More
11 Apr 2023 19:39 #10306 by Barnes
I'm running on latest Mac OS.  I thought the problem was with changes in my src but I think it's how Mac is handling the configure and compile/architecture that is causing this problem.   After downloading a fresh copy of tba,  the mud crashes when I try to look at 2.guard, 2.dandelion, or any number of anything in a room.

 Based on the information in the stack trace, the error occurred in the
Code:
__strcpy_chk
function of the C standard library, which is called by the
Code:
generic_find
function in the
Code:
handler.c
file.The program was trying to copy a string to a destination buffer using
Code:
strcpy
, but the buffer was not large enough to hold the entire string, leading to a buffer overflow and a segmentation fault.

Does anyone here have a suggestion?  Tia.

 * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)  * frame #0: 0x00007ff8012e7d5c libsystem_c.dylib`__chk_fail_overlap + 16    frame #1: 0x00007ff8012710b6 libsystem_c.dylib`__chk_overlap + 34    frame #2: 0x00007ff80127968b libsystem_c.dylib`__strcpy_chk + 64    frame #3: 0x0000000100089d7e circle`generic_find [inlined] get_number(name=<unavailable>) at handler.c:602:5 [opt]    frame #4: 0x0000000100089d1c circle`generic_find(arg=<unavailable>, bitvector=45, ch=0x0000000104b0f8b0, tar_ch=0x00007ff7bfef28a8, tar_obj=0x00007ff7bfef2888) at handler.c:1355:18 [opt]    frame #5: 0x00000001000061e6 circle`look_at_target(ch=0x0000000104b0f8b0, arg=<unavailable>) at act.informative.c:639:10 [opt]    frame #6: 0x0000000100005f7b circle`do_look(ch=0x0000000104b0f8b0, argument=" 2.dandelion", cmd=<unavailable>, subcmd=0) at act.informative.c:0:11 [opt]    frame #7: 0x0000000100098ff1 circle`command_interpreter(ch=0x0000000104b0f8b0, argument=<unavailable>) at interpreter.c:582:6 [opt] 

Please Log in or Create an account to join the conversation.

More
11 Apr 2023 20:23 #10307 by thomas
I see you posted this multiple places, let's just answer here.

The code in question looks like this:
Code:
int get_number(char **name) { int i; char *ppos; char number[MAX_INPUT_LENGTH]; *number = '\0'; if ((ppos = strchr(*name, '.')) != NULL) { *ppos++ = '\0'; strlcpy(number, *name, sizeof(number)); strcpy(*name, ppos); /* strcpy: OK (always smaller) */ // line 602 for (i = 0; *(number + i); i++) if (!isdigit(*(number + i))) return (0); return (atoi(number)); } return (1); }
The code is failing because we are doing naughty stuff here; we are copying a char array over itself (ppos is *name+2 in this case). In most versions of C, this is not really a problem, but apparently Apple dislikes when you do that. The solution is to copy to a temporary char array first:
Code:
int get_number(char **name) { int i; char *ppos; char number[MAX_INPUT_LENGTH]; char tmp[MAX_INPUT_LENGTH]; *number = '\0'; if ((ppos = strchr(*name, '.')) != NULL) { *ppos++ = '\0'; strlcpy(number, *name, sizeof(number)); strlcpy(tmp, ppos, sizeof(tmp)); strcpy(*name, tmp); /* strcpy: OK (always smaller) */ for (i = 0; *(number + i); i++) if (!isdigit(*(number + i))) return (0); return (atoi(number)); } return (1); }
The following user(s) said Thank You: Barnes

Please Log in or Create an account to join the conversation.

More
11 Apr 2023 20:24 #10308 by thomas
of course, the above is browser code, so it may or may not compile ;)
The following user(s) said Thank You: Barnes

Please Log in or Create an account to join the conversation.

Time to create page: 0.624 seconds