OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/secure_socket.h" | 5 #include "bin/secure_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 /* Handle an error reported from the BoringSSL library. */ | 48 /* Handle an error reported from the BoringSSL library. */ |
49 static void ThrowIOException(int status, | 49 static void ThrowIOException(int status, |
50 const char* exception_type, | 50 const char* exception_type, |
51 const char* message, | 51 const char* message, |
52 bool free_message = false) { | 52 bool free_message = false) { |
53 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; | 53 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; |
54 error_string[0] = '\0'; | 54 error_string[0] = '\0'; |
55 int error = ERR_get_error(); | 55 int error = ERR_get_error(); |
56 while (error != 0) { | 56 while (error != 0) { |
57 int length = strnlen(error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE); | 57 int length = strlen(error_string); |
58 int free_length = SSL_ERROR_MESSAGE_BUFFER_SIZE - length; | 58 int free_length = SSL_ERROR_MESSAGE_BUFFER_SIZE - length; |
59 if (free_length > 16) { | 59 if (free_length > 16) { |
60 // Enough room for error code at least. | 60 // Enough room for error code at least. |
61 if (length > 0) { | 61 if (length > 0) { |
62 error_string[length] = '\n'; | 62 error_string[length] = '\n'; |
63 error_string[length + 1] = '\0'; | 63 error_string[length + 1] = '\0'; |
64 length++; | 64 length++; |
65 free_length--; | 65 free_length--; |
66 } | 66 } |
67 ERR_error_string_n(error, error_string + length, free_length); | 67 ERR_error_string_n(error, error_string + length, free_length); |
| 68 // ERR_error_string_n is guaranteed to leave a null-terminated string. |
68 } | 69 } |
69 error = ERR_get_error(); | 70 error = ERR_get_error(); |
70 } | 71 } |
71 OSError os_error_struct(status, error_string, OSError::kBoringSSL); | 72 OSError os_error_struct(status, error_string, OSError::kBoringSSL); |
72 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); | 73 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); |
73 Dart_Handle exception = | 74 Dart_Handle exception = |
74 DartUtils::NewDartIOException(exception_type, message, os_error); | 75 DartUtils::NewDartIOException(exception_type, message, os_error); |
75 if (free_message) { | 76 if (free_message) { |
76 free(const_cast<char*>(message)); | 77 free(const_cast<char*>(message)); |
77 } | 78 } |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 } else { | 1122 } else { |
1122 if (SSL_LOG_DATA) Log::Print( | 1123 if (SSL_LOG_DATA) Log::Print( |
1123 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); | 1124 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); |
1124 } | 1125 } |
1125 } | 1126 } |
1126 return bytes_processed; | 1127 return bytes_processed; |
1127 } | 1128 } |
1128 | 1129 |
1129 } // namespace bin | 1130 } // namespace bin |
1130 } // namespace dart | 1131 } // namespace dart |
OLD | NEW |