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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
Sorry for the bug and thanks for your debugging!
I will take the patch in the next release.