1 // 2 // Copyright (C) Microsoft. All rights reserved. 3 // 4 #include "fxsupportpch.hpp" 5 6 extern "C" { 7 #if defined(EVENT_TRACING) 8 #include "FxRegKey.tmh" 9 #endif 10 } 11 12 _Must_inspect_result_ 13 NTSTATUS 14 FxRegKey::_VerifyMultiSzString( 15 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 16 __in PCUNICODE_STRING RegValueName, 17 __in_bcount(DataLength) PWCHAR DataString, 18 __in ULONG DataLength 19 ) 20 /*++ 21 22 Routine Description: 23 This static function checks the input buffer to verify that it contains 24 a multi-sz string with a double-NULL termination at the end of the buffer. 25 26 Arguments: 27 DataString - buffer containing multi-sz strings. If there are no strings 28 in the buffer, the buffer should at least contain two UNICODE_NULL 29 characters. 30 31 DataLength - the size in bytes of the input buffer. 32 33 Return Value: 34 STATUS_OBJECT_TYPE_MISMATCH - if the the data buffer is off odd-length, 35 or it doesnt end with two UNICODE_NULL characters. 36 37 STATUS_SUCCESS - if the buffer contains valid multi-sz strings. 38 39 --*/ 40 { 41 ULONG numChars; 42 43 if ((DataLength % 2) != 0) { 44 DoTraceLevelMessage( 45 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, 46 "Reg value name %wZ, DataLength %d, Data buffer length is invalid, " 47 "STATUS_OBJECT_TYPE_MISMATCH", 48 RegValueName, DataLength); 49 return STATUS_OBJECT_TYPE_MISMATCH; 50 } 51 52 numChars = DataLength / sizeof(WCHAR); 53 if (numChars < 2 || 54 DataString[numChars-1] != UNICODE_NULL || 55 DataString[numChars-2] != UNICODE_NULL) { 56 57 DoTraceLevelMessage( 58 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, 59 "Read value name %wZ, DataLength %d, Data buffer from registry does not " 60 "have double NULL terminal chars, STATUS_OBJECT_TYPE_MISMATCH", 61 RegValueName, DataLength); 62 return STATUS_OBJECT_TYPE_MISMATCH; 63 } 64 65 return STATUS_SUCCESS; 66 } 67