Menu

Bug in set_encoding()

2009-01-13
2013-05-28
  • Dwayne Boone

    Dwayne Boone - 2009-01-13

    In the set_encoding() function in mbchar.c you do the following:

        strcpy( norm, name);
        if (norm[ 5] == '.')
            memmove( norm, norm + 5, strlen( norm + 5) + 1);
            /* Remove initial 'xxxxx.' as 'ja_JP.', 'en_US.' or any other   */

    This is a bug since you do not check the length of the norm string before accessing norm[5] which may be past the end of the string. Instead it should first check that the string is long enough:

        strcpy( norm, name);
        if (strlen(norm) > 5 && norm[ 5] == '.')
            memmove( norm, norm + 5, strlen( norm + 5) + 1);
            /* Remove initial 'xxxxx.' as 'ja_JP.', 'en_US.' or any other   */

    We were using "-e utf8" and would randomly see mcpp exit with bad encoding which I believe was the result of this issue.

     
    • Kiyoshi Matsui

      Kiyoshi Matsui - 2009-01-14

      Sorry for the bug and thanks for your debugging!
      I will take the patch in the next release.

       

Log in to post a comment.