Changeset 57572 in vbox for trunk/src/VBox/Runtime/common/crypto/pemfile.cpp
- Timestamp:
- Aug 28, 2015 1:31:29 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/pemfile.cpp
r57358 r57572 125 125 uint8_t const *pbSavedContent = pbContent; 126 126 size_t const cbSavedContent = cbContent; 127 uint32_t iMarker = 0; 128 while (iMarker < cMarkers) 127 for (uint32_t iMarker = 0; iMarker < cMarkers; iMarker++) 129 128 { 130 129 pbContent = pbSavedContent; … … 143 142 cbContent -= cchWord; 144 143 145 if (!cbContent || !RT_C_IS_BLANK(*pbContent)) 146 break; 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 144 if (!cbContent) 145 break; 146 if (RT_C_IS_BLANK(*pbContent)) 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 152 else if (cWords > 1 || pbContent[0] != '-') 153 break; 152 154 153 155 cWords--; … … 175 177 if (poffEnd) 176 178 *poffEnd = pbContent - pbStart; 177 if ( *ppMatch)179 if (ppMatch) 178 180 *ppMatch = &paMarkers[iMarker]; 179 181 return true; … … 265 267 { 266 268 /* 267 * Assume a well formed PEM file contains only 7-bit ASCII and restricts268 * itselfto the following control characters:269 * Well formed PEM files should probably only contain 7-bit ASCII and 270 * restrict thenselfs to the following control characters: 269 271 * tab, newline, return, form feed 272 * 273 * However, if we wan't to read PEM files which contains human readable 274 * certificate details before or after each base-64 section, we can't stick 275 * to 7-bit ASCII. We could say it must be UTF-8, but that's probably to 276 * limited too. So, we'll settle for detecting binary files by control 277 * characters alone (safe enough for DER encoded stuff, I think). 270 278 */ 271 279 while (cbFile-- > 0) 272 280 { 273 281 uint8_t const b = *pbFile++; 274 if ( b >= 0x7f 275 || (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') ) 282 if (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') 276 283 { 277 284 /* Ignore EOT (4), SUB (26) and NUL (0) at the end of the file. */ … … 280 287 || ( cbFile == 1 281 288 && *pbFile == '\0'))) 282 return true; 289 return false; 290 283 291 if (b == 0 && cbFile == 0) 284 return true; 285 return false; 286 } 287 } 288 return true; 292 return false; 293 294 return true; 295 } 296 } 297 return false; 289 298 } 290 299 … … 328 337 PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo) 329 338 { 330 AssertReturn(! fFlags, VERR_INVALID_FLAGS);339 AssertReturn(!(fFlags & ~RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR), VERR_INVALID_FLAGS); 331 340 332 341 size_t cbContent; … … 362 371 /* Decode the section. */ 363 372 /** @todo copy the preamble as well. */ 364 rc= rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin,365 (void **)&pSection->pbData, &pSection->cbData);366 if (RT_FAILURE(rc ))373 int rc2 = rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin, 374 (void **)&pSection->pbData, &pSection->cbData); 375 if (RT_FAILURE(rc2)) 367 376 { 368 377 pSection->pbData = NULL; 369 378 pSection->cbData = 0; 370 break; 379 if ( rc2 == VERR_INVALID_BASE64_ENCODING 380 && (fFlags & RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR)) 381 rc = -rc2; 382 else 383 { 384 rc = rc2; 385 break; 386 } 371 387 } 372 388
Note:
See TracChangeset
for help on using the changeset viewer.