Reactos

[NTOS:PNP] Correctly respect data size in PnpRegSzToString. CORE-15766

Spotted by Vadim Galyant.

+13 -4
+13 -4
ntoskrnl/io/pnpmgr/pnputil.c
··· 175 175 PWCHAR p, pp; 176 176 177 177 /* Find the end */ 178 - pp = RegSzData + RegSzLength; 179 - for (p = RegSzData; p < pp; p++) if (!*p) break; 178 + pp = RegSzData + RegSzLength / sizeof(WCHAR); 179 + for (p = RegSzData; p < pp; p++) 180 + { 181 + if (!*p) 182 + { 183 + break; 184 + } 185 + } 180 186 181 - /* Return it */ 182 - if (StringLength) *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR); 187 + /* Return the length. Truncation can happen but is of no consequence. */ 188 + if (StringLength) 189 + { 190 + *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR); 191 + } 183 192 return TRUE; 184 193 } 185 194