Is this a big bug in the implementation of tolower in ntoskrnl.exe?

c, c++, driver, kernel, windows

Solution

`tolower(int c)` is defined only for integers `c`, that are EOF or representable as an unsigned char. `0x7f51` is neither. Therefore, the behaviour of `tolower(0x7f51)` is undefined.

Problem

The following code works fine in user mode: ``` #include <stdio.h> #include <ctype.h> int main() { // // 0x7f51 is the unicode code of Chinese character '网' // int n = tolower(0x7f51); // n will equal 0x7f51 } ``` However, if we are in kernel mode, `n` will equal `0x7f71` !!! The simplest sample code: ``` #include <ntifs.h> ULONG NTAPI DriverEntry(PDRIVER_OBJECT, PUNICODE_STRING) { int n = tolower(0x7f51); // n will equal 0x7f71 !!! return 0; } ``` Is this a big bug in the implementation of `tolower` in ntoskrnl.exe?

Original source