Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: net/ocsp/nss_ocsp.cc

Issue 378003: OCSPTrySendAndReceive should always set *http_response_data_len, even on... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Upload before checkin Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/ocsp/nss_ocsp.h" 5 #include "net/ocsp/nss_ocsp.h"
6 6
7 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424 7 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424
8 // until NSS 3.12.2 comes out and we update to it. 8 // until NSS 3.12.2 comes out and we update to it.
9 #define Lock FOO_NSS_Lock 9 #define Lock FOO_NSS_Lock
10 #include <certt.h> 10 #include <certt.h>
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 const char** http_response_content_type, 416 const char** http_response_content_type,
417 const char** http_response_headers, 417 const char** http_response_headers,
418 const char** http_response_data, 418 const char** http_response_data,
419 PRUint32* http_response_data_len) { 419 PRUint32* http_response_data_len) {
420 DCHECK(req->Finished()); 420 DCHECK(req->Finished());
421 const std::string& data = req->http_response_data(); 421 const std::string& data = req->http_response_data();
422 if (http_response_data_len && *http_response_data_len) { 422 if (http_response_data_len && *http_response_data_len) {
423 if (*http_response_data_len < data.size()) { 423 if (*http_response_data_len < data.size()) {
424 LOG(ERROR) << "data size too large: " << *http_response_data_len 424 LOG(ERROR) << "data size too large: " << *http_response_data_len
425 << " < " << data.size(); 425 << " < " << data.size();
426 *http_response_data_len = 1; 426 *http_response_data_len = data.size();
427 return false; 427 return false;
428 } 428 }
429 } 429 }
430 LOG(INFO) << "OCSP response " 430 LOG(INFO) << "OCSP response "
431 << " response_code=" << req->http_response_code() 431 << " response_code=" << req->http_response_code()
432 << " content_type=" << req->http_response_content_type() 432 << " content_type=" << req->http_response_content_type()
433 << " header=" << req->http_response_headers() 433 << " header=" << req->http_response_headers()
434 << " data_len=" << data.size(); 434 << " data_len=" << data.size();
435 if (http_response_code) 435 if (http_response_code)
436 *http_response_code = req->http_response_code(); 436 *http_response_code = req->http_response_code();
437 if (http_response_content_type) 437 if (http_response_content_type)
438 *http_response_content_type = req->http_response_content_type().c_str(); 438 *http_response_content_type = req->http_response_content_type().c_str();
439 if (http_response_headers) 439 if (http_response_headers)
440 *http_response_headers = req->http_response_headers().c_str(); 440 *http_response_headers = req->http_response_headers().c_str();
441 if (http_response_data) 441 if (http_response_data)
442 *http_response_data = data.data(); 442 *http_response_data = data.data();
443 if (http_response_data_len) 443 if (http_response_data_len)
444 *http_response_data_len = data.size(); 444 *http_response_data_len = data.size();
445 return true; 445 return true;
446 } 446 }
447 447
448 SECStatus OCSPTrySendAndReceive(SEC_HTTP_REQUEST_SESSION request, 448 SECStatus OCSPTrySendAndReceive(SEC_HTTP_REQUEST_SESSION request,
449 PRPollDesc** pPollDesc, 449 PRPollDesc** pPollDesc,
450 PRUint16* http_response_code, 450 PRUint16* http_response_code,
451 const char** http_response_content_type, 451 const char** http_response_content_type,
452 const char** http_response_headers, 452 const char** http_response_headers,
453 const char** http_response_data, 453 const char** http_response_data,
454 PRUint32* http_response_data_len) { 454 PRUint32* http_response_data_len) {
455 LOG(INFO) << "OCSP try start and receive"; 455 LOG(INFO) << "OCSP try send and receive";
456 DCHECK(!MessageLoop::current()); 456 DCHECK(!MessageLoop::current());
457 OCSPRequestSession* req = reinterpret_cast<OCSPRequestSession*>(request); 457 OCSPRequestSession* req = reinterpret_cast<OCSPRequestSession*>(request);
458 // We support blocking mode only. 458 // We support blocking mode only.
459 if (pPollDesc) 459 if (pPollDesc)
460 *pPollDesc = NULL; 460 *pPollDesc = NULL;
461 461
462 if (req->Started() || req->Finished()) { 462 if (req->Started() || req->Finished()) {
463 // We support blocking mode only, so this function shouldn't be called 463 // We support blocking mode only, so this function shouldn't be called
464 // again when req has stareted or finished. 464 // again when req has stareted or finished.
465 NOTREACHED(); 465 NOTREACHED();
466 return SECFailure; 466 goto failed;
467 } 467 }
468 req->Start(); 468 req->Start();
469 if (!req->Wait()) 469 if (!req->Wait())
470 return SECFailure; 470 goto failed;
471 471
472 // If the response code is -1, the request failed and there is no response. 472 // If the response code is -1, the request failed and there is no response.
473 if (req->http_response_code() == static_cast<PRUint16>(-1)) 473 if (req->http_response_code() == static_cast<PRUint16>(-1))
474 return SECFailure; 474 goto failed;
475 475
476 return OCSPSetResponse( 476 return OCSPSetResponse(
477 req, http_response_code, 477 req, http_response_code,
478 http_response_content_type, 478 http_response_content_type,
479 http_response_headers, 479 http_response_headers,
480 http_response_data, 480 http_response_data,
481 http_response_data_len) ? SECSuccess : SECFailure; 481 http_response_data_len) ? SECSuccess : SECFailure;
482
483 failed:
484 if (http_response_data_len) {
485 // We must always set an output value, even on failure. The output value 0
486 // means the failure was unrelated to the acceptable response data length.
487 *http_response_data_len = 0;
488 }
489 return SECFailure;
482 } 490 }
483 491
484 SECStatus OCSPFree(SEC_HTTP_REQUEST_SESSION request) { 492 SECStatus OCSPFree(SEC_HTTP_REQUEST_SESSION request) {
485 LOG(INFO) << "OCSP free"; 493 LOG(INFO) << "OCSP free";
486 DCHECK(!MessageLoop::current()); 494 DCHECK(!MessageLoop::current());
487 OCSPRequestSession* req = reinterpret_cast<OCSPRequestSession*>(request); 495 OCSPRequestSession* req = reinterpret_cast<OCSPRequestSession*>(request);
488 req->Cancel(); 496 req->Cancel();
489 req->Release(); 497 req->Release();
490 return SECSuccess; 498 return SECSuccess;
491 } 499 }
(...skipping 24 matching lines...) Expand all
516 void EnsureOCSPInit() { 524 void EnsureOCSPInit() {
517 Singleton<OCSPInitSingleton>::get(); 525 Singleton<OCSPInitSingleton>::get();
518 } 526 }
519 527
520 // This function would be called before NSS initialization. 528 // This function would be called before NSS initialization.
521 void SetURLRequestContextForOCSP(URLRequestContext* request_context) { 529 void SetURLRequestContextForOCSP(URLRequestContext* request_context) {
522 OCSPInitSingleton::set_url_request_context(request_context); 530 OCSPInitSingleton::set_url_request_context(request_context);
523 } 531 }
524 532
525 } // namespace net 533 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698