Welcome to the Builder Academy

Question Bug in is_name() ?

More
23 May 2024 20:51 #10400 by thomas
Replied by thomas on topic Bug in is_name() ?
My best guess is that it's on different sets of libraries. Do you see any difference between conf.h on those that work and those that don't ?

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

More
24 May 2024 02:51 #10401 by Salty
Replied by Salty on topic Bug in is_name() ?
Code:
salty@ALONE:~$ diff 5.4.0-155-generic_configure 6.8.0-31-generic_configure 0a1,5 > .do if !dPS .ds PS > .do if !dPE .ds PE > .do if !dPF .ds PF > .do if !dPY .ds PY > .lf 1 conf.h 338c343 < #endif /* _CONF_H_ */ \ No newline at end of file --- > #endif /* _CONF_H_ */ salty@ALONE:~$

Issue is present on 5.4.0-155-generic, issue is not present on 6.8.0-31-generic

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

More
21 Jun 2024 12:21 - 21 Jun 2024 12:37 #10408 by thomas
Replied by thomas on topic Bug in is_name() ?
Ok, I've had a closer look at this. It turns out there was a bug in get_number():
Code:
diff --git a/src/handler.c b/src/handler.c index 87269bb..9aeb664 100644 --- a/src/handler.c +++ b/src/handler.c @@ -592,14 +592,16 @@ int get_number(char **name) {   int i;   char *ppos; -  char number[MAX_INPUT_LENGTH]; +  char number[MAX_INPUT_LENGTH], tmp[MAX_INPUT_LENGTH];   *number = '\0';   if ((ppos = strchr(*name, '.')) != NULL) {     *ppos++ = '\0';     strlcpy(number, *name, sizeof(number)); -    strcpy(*name, ppos);      /* strcpy: OK (always smaller) */ +    // avoid overlapping strings in strcpy which is undefined behaviour +    strcpy(tmp, ppos);  /* strcpy: OK (always smaller) */ +    strcpy(*name, tmp);        /* strcpy: OK (always smaller) */     for (i = 0; *(number + i); i++)       if (!isdigit(*(number + i)))
The copy is happening from *name+2 -> *name and that's an overlap that means undefined behavior in strcpy.

This has made me introduce unit testing, because this worked locally, but fortunately failed on the github build.
Feel free to come with feedback on github.com/tbamud/tbamud/pull/134
Last edit: 21 Jun 2024 12:37 by thomas.

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

Time to create page: 0.277 seconds