Changeset 93393 in vbox for trunk/src/VBox/VMM/VMMR3
- Timestamp:
- Jan 21, 2022 11:54:15 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 149489
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/CFGM.cpp
r93392 r93393 68 68 #include <iprt/assert.h> 69 69 #include <iprt/mem.h> 70 #include <iprt/memsafer.h> 70 71 #include <iprt/param.h> 71 72 #include <iprt/string.h> … … 876 877 * @param pszString Where to store the string. 877 878 * @param cchString Size of the string buffer. (Includes terminator.) 879 * 880 * @note Concurrent calls to this function and CFGMR3QueryPasswordDef are not 881 * supported. 878 882 */ 879 883 VMMR3DECL(int) CFGMR3QueryPassword(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString) … … 888 892 if (cchString >= cbSrc) 889 893 { 894 RTMemSaferUnscramble(pLeaf->Value.String.psz, cbSrc); 890 895 memcpy(pszString, pLeaf->Value.String.psz, cbSrc); 891 896 memset(pszString + cbSrc, 0, cchString - cbSrc); 897 RTMemSaferScramble(pLeaf->Value.String.psz, cbSrc); 898 899 Assert(pszString[cbSrc - 1] == '\0'); 892 900 } 893 901 else … … 910 918 * @param cchString Size of the string buffer. (Includes terminator.) 911 919 * @param pszDef The default value. 920 * 921 * @note Concurrent calls to this function and CFGMR3QueryPassword are not 922 * supported. 912 923 */ 913 924 VMMR3DECL(int) CFGMR3QueryPasswordDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef) … … 922 933 if (cchString >= cbSrc) 923 934 { 935 RTMemSaferUnscramble(pLeaf->Value.String.psz, cbSrc); 924 936 memcpy(pszString, pLeaf->Value.String.psz, cbSrc); 925 937 memset(pszString + cbSrc, 0, cchString - cbSrc); 938 RTMemSaferScramble(pLeaf->Value.String.psz, cbSrc); 939 940 Assert(pszString[cbSrc - 1] == '\0'); 926 941 } 927 942 else … … 2115 2130 break; 2116 2131 2117 case CFGMVALUETYPE_PASSWORD:2118 RTMemWipeThoroughly(pLeaf->Value.String.psz, pLeaf->Value.String.cb, 10);2119 RT_FALL_THROUGH();2120 2132 case CFGMVALUETYPE_STRING: 2121 2133 cfgmR3StrFree(pVM, pLeaf->Value.String.psz); … … 2124 2136 break; 2125 2137 2138 case CFGMVALUETYPE_PASSWORD: 2139 RTMemSaferFree(pLeaf->Value.String.psz, pLeaf->Value.String.cb); 2140 pLeaf->Value.String.psz = NULL; 2141 pLeaf->Value.String.cb = 0; 2142 break; 2143 2126 2144 case CFGMVALUETYPE_INTEGER: 2127 2145 break; … … 2171 2189 2172 2190 /** 2173 * Inserts a new string value. This variant expects that the caller know the length 2174 * of the string already so we can avoid calling strlen() here. 2191 * Inserts a new string value. 2192 * 2193 * This variant expects that the caller know the length of the string already so 2194 * we can avoid calling strlen() here. 2175 2195 * 2176 2196 * @returns VBox status code. … … 2222 2242 2223 2243 /** 2224 * Inserts a new string value. Calls strlen(pszString) internally; if you know the 2225 * length of the string, CFGMR3InsertStringLengthKnown() is faster. 2244 * Inserts a new string value. 2245 * 2246 * Calls strlen(pszString) internally; if you know the length of the string, 2247 * CFGMR3InsertStringLengthKnown() is faster. 2226 2248 * 2227 2249 * @returns VBox status code. … … 2327 2349 2328 2350 /** 2329 * Inserts a new integervalue.2351 * Inserts a new bytes value. 2330 2352 * 2331 2353 * @returns VBox status code. … … 2378 2400 2379 2401 /** 2380 * Inserts a new password value. This variant expects that the caller know the length 2381 * of the password string already so we can avoid calling strlen() here. 2402 * Inserts a new password value. 2403 * 2404 * This variant expects that the caller know the length of the password string 2405 * already so we can avoid calling strlen() here. 2382 2406 * 2383 2407 * @returns VBox status code. … … 2385 2409 * @param pszName Value name. 2386 2410 * @param pszString The value. Must not be NULL. 2387 * @param cchString The length of the string excluding the 2388 * terminator. 2411 * @param cchString The length of the string excluding the terminator. 2389 2412 */ 2390 2413 VMMR3DECL(int) CFGMR3InsertPasswordN(PCFGMNODE pNode, const char *pszName, const char *pszString, size_t cchString) … … 2396 2419 { 2397 2420 /* 2398 * Allocate string object first. 2421 * Allocate string object first using the safer memory API since this 2422 * is considered sensitive information. 2399 2423 */ 2400 char *pszStringCopy = (char *) cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_STRING,cchString + 1);2424 char *pszStringCopy = (char *)RTMemSaferAllocZ(cchString + 1); 2401 2425 if (pszStringCopy) 2402 2426 { 2403 2427 memcpy(pszStringCopy, pszString, cchString); 2404 2428 pszStringCopy[cchString] = '\0'; 2429 RTMemSaferScramble(pszStringCopy, cchString + 1); 2405 2430 2406 2431 /* … … 2416 2441 } 2417 2442 else 2418 { 2419 RTMemWipeThoroughly(pszStringCopy, cchString, 10); 2420 cfgmR3StrFree(pNode->pVM, pszStringCopy); 2421 } 2443 RTMemSaferFree(pszStringCopy, cchString + 1); 2422 2444 } 2423 2445 else … … 2432 2454 2433 2455 /** 2434 * Inserts a new password value. Calls strlen(pszString) internally; if you know the 2435 * length of the string, CFGMR3InsertStringLengthKnown() is faster. 2456 * Inserts a new password value. 2457 * 2458 * Calls strlen(pszString) internally; if you know the length of the string, 2459 * CFGMR3InsertStringLengthKnown() is faster. 2436 2460 * 2437 2461 * @returns VBox status code.
Note:
See TracChangeset
for help on using the changeset viewer.