crash in command_interpreter() with part of Unicode-characters

  • Pacifist
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 month ago #10028 by Pacifist
I found that part of command_interpreter() cause crash with such commands like "ю", "юю" etc. It's occur there:
  /* special case to handle one-character, non-alphanumeric commands; requested
   * by many people so "'hi" or ";godnet test" is possible. Patch sent by Eric
   * Green and Stefan Wasilewski. */
  if (!isalpha(*argument)) {
    arg[0] = argument[0];
    arg[1] = '\0';
    line = argument + 1;
  } else
    line = any_one_arg(argument, arg);

How can I repair that?

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

More
1 year 1 month ago #10029 by thomas
This is a special case where your characters trigger the "not alphanumeric" check. I figure this results in garbage in the resulting values.
The fix is to rewrite to using iswalpha instead, though I'm not sure how to go about it here.

Have you altered the code significantly to support utf-8 by now?

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

  • Pacifist
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 month ago #10030 by Pacifist
Have you altered the code significantly to support utf-8 by now?

I'm use only this modification:
github.com/prool/tbamud/blob/7790abec579...590/src/comm.c#L1965

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

More
1 year 1 month ago #10031 by thomas
Ok, I understand why this happens now (thanks for the link to the code, it really helped). The issue is that the isalpha check returns false for the koi characters (are they utf-8-encoded here? I think so).
Instead of
 if (!isalpha(*argument)) {
I suggest you be explicit like this:
// somewhere near the function.
const char specialSingleChars = "*';";

 if (strchr(specialSingleChars, *argument) != NULL) {

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

  • Pacifist
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 month ago #10032 by Pacifist
interpreter.c: In function ‘command_interpreter’:
interpreter.c:488:35: warning: initialization of ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]
  488 |   const char specialSingleChars = "*';";
      |                                   ^~~~~
interpreter.c:500:14: warning: passing argument 1 of ‘strchr’ makes pointer from integer without a cast [-Wint-conversion]
  500 |   if (strchr(specialSingleChars, *argument) != NULL) {
      |              ^~~~~~~~~~~~~~~~~~
      |              |
      |              char
In file included from sysdep.h:74,
                 from interpreter.c:12:
/usr/include/string.h:226:14: note: expected ‘const char *’ but argument is of type ‘char’
  226 | extern char *strchr (const char *__s, int __c)
      |              ^~~~~~
And TbaMUD crashed soon after run.

I'm not programmer but think that problem in "ю" that it wide character and occupy more than argument[0].

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

More
1 year 1 month ago #10033 by thomas
Ah yes, a typical browser code slip.
Missed a * there.
const char *specialSingleChars = "*';";

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

  • Pacifist
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 month ago #10034 by Pacifist
Thanks. It working now.

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

Time to create page: 0.105 seconds