Changeset 100542 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 12, 2023 11:23:07 AM (21 months ago)
- svn:sync-xref-src-repo-rev:
- 158356
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/DevFwCommon.cpp
r98103 r100542 46 46 #include <iprt/system.h> 47 47 #include <iprt/cdefs.h> 48 #include <iprt/alloca.h> 48 49 49 50 #include "VBoxDD.h" … … 435 436 436 437 /** 438 * Replace the DmiSystemUuid placeholder with the actual value. 439 * 440 * @param pszBuf Buffer 441 * @param cbBuf Size of buffer 442 * @param pcszPlaceholder Pointer to placeholder, must be in pszBuf 443 * @param cbPlaceholder Length of placeholder 444 * @param pcszDmiSystemUuid DmiSystemUuid value 445 */ 446 static void fwUseDmiSystemUuidInString(char *pszBuf, size_t cbBuf, 447 const char *pcszPlaceholder, size_t cbPlaceholder, 448 const char *pcszDmiSystemUuid) 449 { 450 size_t const cbPrefix = pcszPlaceholder - pszBuf; 451 size_t const cbUuid = strlen(pcszDmiSystemUuid); 452 size_t const cbSuffix = strlen(pcszPlaceholder + cbPlaceholder); 453 if (cbPrefix + cbUuid + cbSuffix < cbBuf) 454 { 455 /* Everything fits, no truncation. */ 456 memmove(pszBuf + cbPrefix + cbUuid, pcszPlaceholder + cbPlaceholder, cbSuffix + 1); \ 457 memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbUuid); \ 458 } 459 else if (cbPrefix + cbUuid < cbBuf) 460 { 461 /* Prefix + DmiSystemUuid fits, truncate suffix. */ 462 memmove(pszBuf + cbPrefix + cbUuid, pcszPlaceholder + cbPlaceholder, cbBuf - cbPrefix - cbUuid - 1); \ 463 memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbUuid); \ 464 pszBuf[cbBuf] = '\0'; 465 } 466 else 467 { 468 /* Prefix fits, truncate DmiSystemUuid. */ 469 memcpy(pszBuf + cbPrefix, pcszDmiSystemUuid, cbBuf - cbPrefix - 1); \ 470 pszBuf[cbBuf] = '\0'; 471 } 472 } 473 474 /** 437 475 * Construct the DMI table. 438 476 * … … 501 539 if (!strcmp(szBuf, "<EMPTY>")) \ 502 540 pszTmp = ""; \ 541 else if ((pszTmp = RTStrStr(szBuf, "<DmiSystemUuid>"))) \ 542 { \ 543 char *pszUuid = pszDmiSystemUuid; \ 544 if (!pszUuid) \ 545 { \ 546 pszUuid = (char *)alloca(RTUUID_STR_LENGTH); \ 547 RTUuidToStr(pUuid, pszUuid, RTUUID_STR_LENGTH); \ 548 } \ 549 fwUseDmiSystemUuidInString(szBuf, sizeof(szBuf), pszTmp, 15, pszUuid); \ 550 pszTmp = szBuf; \ 551 } \ 503 552 else \ 504 553 pszTmp = szBuf; \
Note:
See TracChangeset
for help on using the changeset viewer.