Commit 71d02eeccacd0fc84b6999a65756d34458cae271
1 parent
6b1178c2
Exists in
master
and in
3 other branches
Fixing segfault on windows.
Showing
1 changed file
with
53 additions
and
24 deletions
Show diff stats
src/lib3270/windows/connect.c
... | ... | @@ -236,6 +236,22 @@ int lib3270_reconnect(H3270 *hSession, int seconds) |
236 | 236 | if(hSession->sock > 0) |
237 | 237 | return errno = EBUSY; |
238 | 238 | |
239 | + if(!(hSession->host.current && hSession->host.srvc)) | |
240 | + { | |
241 | + // No host info, try the default one. | |
242 | + if(lib3270_set_url(hSession,NULL)) | |
243 | + { | |
244 | + int err = errno; | |
245 | + lib3270_trace_event(hSession,"Can't set default URL (%s)\n",strerror(err)); | |
246 | + return errno = err; | |
247 | + } | |
248 | + | |
249 | + if(!(hSession->host.current && hSession->host.srvc)) | |
250 | + { | |
251 | + return errno = ENOENT; | |
252 | + } | |
253 | + } | |
254 | + | |
239 | 255 | sockstart(hSession); |
240 | 256 | |
241 | 257 | #if defined(HAVE_LIBSSL) |
... | ... | @@ -253,36 +269,49 @@ int lib3270_reconnect(H3270 *hSession, int seconds) |
253 | 269 | { |
254 | 270 | lib3270_autoptr(char) message = lib3270_strdup_printf(_( "Can't connect to %s"), lib3270_get_url(hSession)); |
255 | 271 | |
256 | - char msg[4096]; | |
257 | - strncpy(msg,host.message,4095); | |
272 | + if(host.message) | |
273 | + { | |
274 | + char msg[4096]; | |
275 | + strncpy(msg,host.message,4095); | |
258 | 276 | |
259 | 277 | #ifdef HAVE_ICONV |
260 | - if(host.convert) | |
261 | - { | |
262 | - char * ptr = msg; | |
263 | - size_t out = 4096; | |
264 | - size_t in = strlen(host.message); | |
265 | - | |
266 | - iconv_t hConv = iconv_open(lib3270_win32_local_charset(),"UTF-8"); | |
267 | - if(iconv( | |
268 | - hConv, | |
269 | - &host.message,&in, | |
270 | - &ptr,&out | |
271 | - ) == ((size_t) -1)) | |
278 | + if(host.convert) | |
272 | 279 | { |
273 | - strncpy(msg,host.message,4095); | |
274 | - } | |
275 | - iconv_close(hConv); | |
280 | + char * ptr = msg; | |
281 | + size_t out = 4096; | |
282 | + size_t in = strlen(host.message); | |
283 | + | |
284 | + iconv_t hConv = iconv_open(lib3270_win32_local_charset(),"UTF-8"); | |
285 | + if(iconv( | |
286 | + hConv, | |
287 | + &host.message,&in, | |
288 | + &ptr,&out | |
289 | + ) == ((size_t) -1)) | |
290 | + { | |
291 | + strncpy(msg,host.message,4095); | |
292 | + } | |
293 | + iconv_close(hConv); | |
276 | 294 | |
277 | - } | |
295 | + } | |
278 | 296 | #endif // HAVE_ICONV |
279 | 297 | |
280 | - lib3270_popup_dialog( hSession, | |
281 | - LIB3270_NOTIFY_ERROR, | |
282 | - _( "Connection error" ), | |
283 | - message, | |
284 | - "%s", | |
285 | - msg); | |
298 | + lib3270_popup_dialog( hSession, | |
299 | + LIB3270_NOTIFY_ERROR, | |
300 | + _( "Connection error" ), | |
301 | + message, | |
302 | + "%s", | |
303 | + NULL); | |
304 | + | |
305 | + } | |
306 | + else | |
307 | + { | |
308 | + lib3270_popup_dialog( hSession, | |
309 | + LIB3270_NOTIFY_ERROR, | |
310 | + _( "Connection error" ), | |
311 | + message, | |
312 | + "%s", | |
313 | + NULL); | |
314 | + } | |
286 | 315 | |
287 | 316 | lib3270_set_disconnected(hSession); |
288 | 317 | return errno = ENOTCONN; | ... | ... |