Commit c119b21be8d91747fa133874a666c24361b3b2a6
1 parent
5138be21
Exists in
master
and in
3 other branches
Fixing segfault on invalid clipboard contents.
Showing
2 changed files
with
27 additions
and
20 deletions
Show diff stats
src/core/paste.c
... | ... | @@ -371,39 +371,42 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str, |
371 | 371 | return rc; |
372 | 372 | } |
373 | 373 | |
374 | -LIB3270_EXPORT int lib3270_paste_text(H3270 *h, const unsigned char *str) | |
374 | +LIB3270_EXPORT int lib3270_paste_text(H3270 *hSession, const unsigned char *str) | |
375 | 375 | { |
376 | - int sz; | |
377 | - CHECK_SESSION_HANDLE(h); | |
376 | + if(check_online_session(hSession)) | |
377 | + return -errno; | |
378 | 378 | |
379 | - if(!lib3270_is_connected(h)) | |
379 | + if(!str) | |
380 | 380 | { |
381 | - lib3270_ring_bell(h); | |
382 | - errno = ENOTCONN; | |
383 | - return 0; | |
381 | + lib3270_ring_bell(hSession); | |
382 | + return -(errno = EINVAL); | |
384 | 383 | } |
385 | 384 | |
386 | - if(h->paste_buffer) | |
385 | + if(hSession->paste_buffer) | |
387 | 386 | { |
388 | - lib3270_free(h->paste_buffer); | |
389 | - h->paste_buffer = NULL; | |
387 | + lib3270_free(hSession->paste_buffer); | |
388 | + hSession->paste_buffer = NULL; | |
390 | 389 | } |
391 | 390 | |
392 | - sz = lib3270_set_string(h,str,-1); | |
391 | + int sz = lib3270_set_string(hSession,str,-1); | |
393 | 392 | if(sz < 0) |
394 | 393 | { |
395 | 394 | // Can´t paste |
396 | - lib3270_popup_dialog(h,LIB3270_NOTIFY_WARNING, | |
397 | - _( "Action failed" ), | |
398 | - _( "Unable to paste text" ), | |
399 | - "%s", sz == -EPERM ? _( "Keyboard is locked" ) : _( "Unexpected error" ) ); | |
400 | - return 0; | |
395 | + lib3270_popup_dialog( | |
396 | + hSession, | |
397 | + LIB3270_NOTIFY_WARNING, | |
398 | + _( "Action failed" ), | |
399 | + _( "Unable to paste text" ), | |
400 | + "%s", sz == -EPERM ? _( "Keyboard is locked" ) : _( "Unexpected error" ) | |
401 | + ); | |
402 | + | |
403 | + return sz; | |
401 | 404 | } |
402 | 405 | |
403 | 406 | if((int) strlen((char *) str) > sz) |
404 | 407 | { |
405 | - h->paste_buffer = strdup((char *) (str+sz)); | |
406 | - return 1; | |
408 | + hSession->paste_buffer = strdup((char *) (str+sz)); | |
409 | + return strlen(hSession->paste_buffer); | |
407 | 410 | } |
408 | 411 | |
409 | 412 | return 0; | ... | ... |
src/include/lib3270/selection.h
... | ... | @@ -105,10 +105,14 @@ |
105 | 105 | * |
106 | 106 | * @see lib3270_paste_next. |
107 | 107 | * |
108 | - * @return Non 0 if there's more to paste with lib3270_pastenext. | |
108 | + * @return 0 if suceeded, negative if faile, > 0 if there's more data. | |
109 | + * | |
110 | + * @retval 0 The entire string was pasted. | |
111 | + * @retval -EINVAL Invalid argument. | |
112 | + * @retval -EPERM Keyboard is locked. | |
109 | 113 | * |
110 | 114 | */ |
111 | - LIB3270_EXPORT int lib3270_paste_text(H3270 *h, const unsigned char *str); | |
115 | + LIB3270_EXPORT int lib3270_paste_text(H3270 *hSession, const unsigned char *str); | |
112 | 116 | |
113 | 117 | /** |
114 | 118 | * @brief Paste remaining string. | ... | ... |