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

Side by Side Diff: net/http/http_auth_gssapi_posix.cc

Issue 2646004: More robust handling of GSSAPI error strings... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Individual status message limit of 4K, total message of 8K-1 Created 10 years, 6 months 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')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/http/http_auth_gssapi_posix.h" 5 #include "net/http/http_auth_gssapi_posix.h"
6 6
7 #include <limits>
8
7 #include "base/base64.h" 9 #include "base/base64.h"
8 #include "base/file_path.h" 10 #include "base/file_path.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/singleton.h" 12 #include "base/singleton.h"
11 #include "base/string_util.h" 13 #include "base/string_util.h"
12 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
13 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
14 16
15 namespace { 17 namespace {
16 18
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 gssapi::OM_uint32 minor_status) { 203 gssapi::OM_uint32 minor_status) {
202 if (major_status == GSS_S_COMPLETE) 204 if (major_status == GSS_S_COMPLETE)
203 return "OK"; 205 return "OK";
204 return StringPrintf("0x%08x 0x%08x", major_status, minor_status); 206 return StringPrintf("0x%08x 0x%08x", major_status, minor_status);
205 } 207 }
206 208
207 std::string DisplayCode(GSSAPILibrary* gssapi_lib, 209 std::string DisplayCode(GSSAPILibrary* gssapi_lib,
208 gssapi::OM_uint32 status, 210 gssapi::OM_uint32 status,
209 gssapi::OM_uint32 status_code_type) { 211 gssapi::OM_uint32 status_code_type) {
210 const int kMaxDisplayIterations = 8; 212 const int kMaxDisplayIterations = 8;
213 const size_t kMaxMsgLength = 4096;
211 // msg_ctx needs to be outside the loop because it is invoked multiple times. 214 // msg_ctx needs to be outside the loop because it is invoked multiple times.
212 gssapi::OM_uint32 msg_ctx = 0; 215 gssapi::OM_uint32 msg_ctx = 0;
213 std::string rv = StringPrintf("(0x%08X)", status); 216 std::string rv = StringPrintf("(0x%08X)", status);
214 217
215 // This loop should continue iterating until msg_ctx is 0 after the first 218 // This loop should continue iterating until msg_ctx is 0 after the first
216 // iteration. To be cautious and prevent an infinite loop, it stops after 219 // iteration. To be cautious and prevent an infinite loop, it stops after
217 // a finite number of iterations as well. 220 // a finite number of iterations as well. As an added sanity check, no
218 for (int i = 0; i < kMaxDisplayIterations; ++i) { 221 // individual message may exceed |kMaxMsgLength|, and the final result
222 // will not exceed |kMaxMsgLength|*2-1.
223 for (int i = 0; i < kMaxDisplayIterations && rv.size() < kMaxMsgLength;
224 ++i) {
219 gssapi::OM_uint32 min_stat; 225 gssapi::OM_uint32 min_stat;
wtc 2010/06/12 00:25:33 Andy, could you rename min_stat to minor_status an
220 gssapi::gss_buffer_desc_struct msg = GSS_C_EMPTY_BUFFER; 226 gssapi::gss_buffer_desc_struct msg = GSS_C_EMPTY_BUFFER;
221 gssapi_lib->display_status(&min_stat, status, status_code_type, 227 gssapi::OM_uint32 maj_stat =
222 GSS_C_NULL_OID, 228 gssapi_lib->display_status(&min_stat, status, status_code_type,
223 &msg_ctx, &msg); 229 GSS_C_NULL_OID, &msg_ctx, &msg);
224 rv += StringPrintf(" %s", static_cast<char *>(msg.value)); 230 if (maj_stat == GSS_S_COMPLETE) {
231 int msg_len = (msg.length > kMaxMsgLength) ?
232 static_cast<int>(kMaxMsgLength) :
233 static_cast<int>(msg.length);
234 if (msg_len > 0 && msg.value != NULL) {
235 rv += StringPrintf(" %.*s", msg_len,
236 static_cast<char *>(msg.value));
237 }
238 }
225 gssapi_lib->release_buffer(&min_stat, &msg); 239 gssapi_lib->release_buffer(&min_stat, &msg);
226 if (!msg_ctx) 240 if (!msg_ctx)
227 break; 241 break;
228 } 242 }
229 return rv; 243 return rv;
230 } 244 }
231 245
232 std::string DisplayExtendedStatus(GSSAPILibrary* gssapi_lib, 246 std::string DisplayExtendedStatus(GSSAPILibrary* gssapi_lib,
233 gssapi::OM_uint32 major_status, 247 gssapi::OM_uint32 major_status,
234 gssapi::OM_uint32 minor_status) { 248 gssapi::OM_uint32 minor_status) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 major_status, 459 major_status,
446 minor_status); 460 minor_status);
447 return ERR_UNEXPECTED; 461 return ERR_UNEXPECTED;
448 } 462 }
449 463
450 return (major_status != GSS_S_COMPLETE) ? ERR_IO_PENDING : OK; 464 return (major_status != GSS_S_COMPLETE) ? ERR_IO_PENDING : OK;
451 } 465 }
452 466
453 } // namespace net 467 } // namespace net
454 468
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