Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix out-of-bounds read in ChemistryStr
- Check BATTERY_INFORMATION Chemistry[4] for null terminator. Chemistry is a string that is "not necessarily zero-terminated". Prior to this change ChemistryStr() did not check for null and incorrectly used sizeof to get the read size of parameter UCHAR Chemistry[4] which decays to UCHAR *Chemistry. For 32-bit builds ChemistryStr happened to work by luck, though it may have read the null into std::string. MS currently uses only strings of length 3 or 4, and the size of *Chemistry is 4 so ChemistryStr never read past 4 bytes. For example {'N','i','Z','n'} or {'R','A','M','\0'}. For 64-bit builds the pointer size is 8 and it read at least 4 bytes too many. Ref: https://docs.microsoft.com/en-us/windows/win32/power/battery-information-str
- Loading branch information