OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 string *error_description) { | 65 string *error_description) { |
66 if (response_code != NULL) | 66 if (response_code != NULL) |
67 *response_code = 0; | 67 *response_code = 0; |
68 | 68 |
69 if (!CheckParameters(parameters)) | 69 if (!CheckParameters(parameters)) |
70 return false; | 70 return false; |
71 | 71 |
72 // We may have been linked statically; if curl_easy_init is in the | 72 // We may have been linked statically; if curl_easy_init is in the |
73 // current binary, no need to search for a dynamic version. | 73 // current binary, no need to search for a dynamic version. |
74 void* curl_lib = dlopen(NULL, RTLD_NOW); | 74 void* curl_lib = dlopen(NULL, RTLD_NOW); |
75 if (!curl_lib || dlsym(curl_lib, "curl_easy_init") == NULL) { | 75 if (!CheckCurlLib(curl_lib)) { |
| 76 fprintf(stderr, |
| 77 "Failed to open curl lib from binary, use libcurl.so instead\n"); |
76 dlerror(); // Clear dlerror before attempting to open libraries. | 78 dlerror(); // Clear dlerror before attempting to open libraries. |
77 dlclose(curl_lib); | 79 dlclose(curl_lib); |
78 curl_lib = NULL; | 80 curl_lib = NULL; |
79 } | 81 } |
80 if (!curl_lib) { | 82 if (!curl_lib) { |
81 curl_lib = dlopen("libcurl.so", RTLD_NOW); | 83 curl_lib = dlopen("libcurl.so", RTLD_NOW); |
82 } | 84 } |
83 if (!curl_lib) { | 85 if (!curl_lib) { |
84 if (error_description != NULL) | 86 if (error_description != NULL) |
85 *error_description = dlerror(); | 87 *error_description = dlerror(); |
(...skipping 20 matching lines...) Expand all Loading... |
106 if (!curl) { | 108 if (!curl) { |
107 dlclose(curl_lib); | 109 dlclose(curl_lib); |
108 return false; | 110 return false; |
109 } | 111 } |
110 | 112 |
111 CURLcode err_code = CURLE_OK; | 113 CURLcode err_code = CURLE_OK; |
112 CURLcode (*curl_easy_setopt)(CURL *, CURLoption, ...); | 114 CURLcode (*curl_easy_setopt)(CURL *, CURLoption, ...); |
113 *(void**) (&curl_easy_setopt) = dlsym(curl_lib, "curl_easy_setopt"); | 115 *(void**) (&curl_easy_setopt) = dlsym(curl_lib, "curl_easy_setopt"); |
114 (*curl_easy_setopt)(curl, CURLOPT_URL, url.c_str()); | 116 (*curl_easy_setopt)(curl, CURLOPT_URL, url.c_str()); |
115 (*curl_easy_setopt)(curl, CURLOPT_USERAGENT, kUserAgent); | 117 (*curl_easy_setopt)(curl, CURLOPT_USERAGENT, kUserAgent); |
| 118 // Support multithread by disabling timeout handling, would get SIGSEGV with |
| 119 // Curl_resolv_timeout in stack trace otherwise. |
| 120 // See https://curl.haxx.se/libcurl/c/threadsafe.html |
| 121 (*curl_easy_setopt)(curl, CURLOPT_NOSIGNAL, 1); |
116 // Set proxy information if necessary. | 122 // Set proxy information if necessary. |
117 if (!proxy.empty()) | 123 if (!proxy.empty()) |
118 (*curl_easy_setopt)(curl, CURLOPT_PROXY, proxy.c_str()); | 124 (*curl_easy_setopt)(curl, CURLOPT_PROXY, proxy.c_str()); |
119 if (!proxy_user_pwd.empty()) | 125 if (!proxy_user_pwd.empty()) |
120 (*curl_easy_setopt)(curl, CURLOPT_PROXYUSERPWD, proxy_user_pwd.c_str()); | 126 (*curl_easy_setopt)(curl, CURLOPT_PROXYUSERPWD, proxy_user_pwd.c_str()); |
121 | 127 |
122 if (!ca_certificate_file.empty()) | 128 if (!ca_certificate_file.empty()) |
123 (*curl_easy_setopt)(curl, CURLOPT_CAINFO, ca_certificate_file.c_str()); | 129 (*curl_easy_setopt)(curl, CURLOPT_CAINFO, ca_certificate_file.c_str()); |
124 | 130 |
125 struct curl_httppost *formpost = NULL; | 131 struct curl_httppost *formpost = NULL; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 if (headerlist != NULL) { | 197 if (headerlist != NULL) { |
192 void (*curl_slist_free_all)(struct curl_slist *); | 198 void (*curl_slist_free_all)(struct curl_slist *); |
193 *(void**) (&curl_slist_free_all) = dlsym(curl_lib, "curl_slist_free_all"); | 199 *(void**) (&curl_slist_free_all) = dlsym(curl_lib, "curl_slist_free_all"); |
194 (*curl_slist_free_all)(headerlist); | 200 (*curl_slist_free_all)(headerlist); |
195 } | 201 } |
196 dlclose(curl_lib); | 202 dlclose(curl_lib); |
197 return err_code == CURLE_OK; | 203 return err_code == CURLE_OK; |
198 } | 204 } |
199 | 205 |
200 // static | 206 // static |
| 207 bool HTTPUpload::CheckCurlLib(void* curl_lib) { |
| 208 return curl_lib && |
| 209 dlsym(curl_lib, "curl_easy_init") && |
| 210 dlsym(curl_lib, "curl_easy_setopt"); |
| 211 } |
| 212 |
| 213 // static |
201 bool HTTPUpload::CheckParameters(const map<string, string> ¶meters) { | 214 bool HTTPUpload::CheckParameters(const map<string, string> ¶meters) { |
202 for (map<string, string>::const_iterator pos = parameters.begin(); | 215 for (map<string, string>::const_iterator pos = parameters.begin(); |
203 pos != parameters.end(); ++pos) { | 216 pos != parameters.end(); ++pos) { |
204 const string &str = pos->first; | 217 const string &str = pos->first; |
205 if (str.size() == 0) | 218 if (str.size() == 0) |
206 return false; // disallow empty parameter names | 219 return false; // disallow empty parameter names |
207 for (unsigned int i = 0; i < str.size(); ++i) { | 220 for (unsigned int i = 0; i < str.size(); ++i) { |
208 int c = str[i]; | 221 int c = str[i]; |
209 if (c < 32 || c == '"' || c > 127) { | 222 if (c < 32 || c == '"' || c > 127) { |
210 return false; | 223 return false; |
211 } | 224 } |
212 } | 225 } |
213 } | 226 } |
214 return true; | 227 return true; |
215 } | 228 } |
216 | 229 |
217 } // namespace google_breakpad | 230 } // namespace google_breakpad |
OLD | NEW |