Changeset 40058 in vbox
- Timestamp:
- Feb 10, 2012 1:10:26 PM (13 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/base64.cpp
r33540 r40058 424 424 cch /= 6; 425 425 426 cch += (cch / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 427 cch -= (cch % RTBASE64_LINE_LEN) == 0; 426 cch += ((cch - 1) / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 428 427 return cch; 429 428 } … … 434 433 cch /= 6; 435 434 436 cch += (cch / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 437 cch -= (cch % RTBASE64_LINE_LEN) == 0; 435 cch += ((cch - 1) / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 438 436 return cch; 439 437 } -
trunk/src/VBox/Runtime/testcase/tstRTBase64.cpp
r28800 r40058 5 5 6 6 /* 7 * Copyright (C) 2009 Oracle Corporation7 * Copyright (C) 2009-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 173 173 174 174 /* 175 * Test for buffer overruns. 176 */ 177 static uint8_t s_abData4[32768]; 178 for (size_t i = 0; i < sizeof(s_abData4); i++) 179 s_abData4[i] = i % 256; 180 for (size_t cbSrc = 1; cbSrc <= sizeof(s_abData4); cbSrc++) 181 { 182 RTTestSubF(hTest, "Test 3-%zu", cbSrc); 183 char szEnc[49152]; 184 memset(szEnc, '\0', sizeof(szEnc)); 185 size_t cchEnc = RTBase64EncodedLength(cbSrc); 186 if (cchEnc >= sizeof(szEnc)) 187 RTTestIFailed("RTBase64EncodedLength returned %zu bytes, too big\n", cchEnc); 188 size_t cchOut = 0; 189 rc = RTBase64Encode(s_abData4, cbSrc, szEnc, cchEnc, &cchOut); 190 if (rc != VERR_BUFFER_OVERFLOW) 191 RTTestIFailed("RTBase64Encode has no buffer overflow with too small buffer -> %Rrc\n", rc); 192 rc = RTBase64Encode(s_abData4, cbSrc, szEnc, cchEnc + 1, &cchOut); 193 if (RT_FAILURE(rc)) 194 RTTestIFailed("RTBase64Encode -> %Rrc\n", rc); 195 if (cchOut != cchEnc) 196 RTTestIFailed("RTBase64EncodedLength returned %zu bytes, expected %zu.\n", 197 cchEnc, cchOut); 198 if (szEnc[cchOut + 1] != '\0') 199 RTTestIFailed("RTBase64Encode returned string which is not zero terminated\n"); 200 if (strlen(szEnc) != cchOut) 201 RTTestIFailed("RTBase64Encode returned incorrect string, length %lu\n", cchOut); 202 } 203 204 /* 175 205 * Finally, a more extensive test. 176 206 */ 177 RTTestSub(hTest, "Test 3");207 RTTestSub(hTest, "Test 4"); 178 208 static uint8_t s_abData3[12*256]; 179 209 for (unsigned i = 0; i < 256; i++)
Note:
See TracChangeset
for help on using the changeset viewer.