diff --git a/src/core/ansi.c b/src/core/ansi.c index 02bcd57..cf5de8b 100644 --- a/src/core/ansi.c +++ b/src/core/ansi.c @@ -1729,7 +1729,7 @@ ansi_send_pf(H3270 *hSession, int nn) { if (nn < 1 || ((size_t) nn) > sizeof(code)/sizeof(code[0])) return; - (void) sprintf(fn_buf, "\033[%d~", code[nn-1]); + (void) snprintf(fn_buf, sizeof(fn_buf), "\033[%d~", code[nn-1]); net_sends(hSession,fn_buf); } diff --git a/src/core/cursor.c b/src/core/cursor.c index 51d5521..80d5284 100644 --- a/src/core/cursor.c +++ b/src/core/cursor.c @@ -90,7 +90,8 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u status_reset(hSession); } else { struct ta *ta = new_ta(hSession, TA_TYPE_CURSOR_MOVE); - + if(!ta) + return -1; ta->args.move.direction = dir; ta->args.move.fn = lib3270_move_cursor; ta->args.move.sel = sel; diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index f168265..71aab62 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -128,14 +128,16 @@ static const char dxl[] = "0123456789abcdef"; * Check for typeahead availability and create a new TA structure. * * @return new typeahead struct or NULL if it's not available. + * @retval NULL Host is not connected or malloc error. */ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { - struct ta *ta; + struct ta *ta = NULL; // If no connection, forget it. if (!lib3270_is_connected(hSession)) { lib3270_ring_bell(hSession); lib3270_write_event_trace(hSession,"typeahead action dropped (not connected)\n"); + errno = ENOTCONN; return NULL; } @@ -143,6 +145,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { if (hSession->kybdlock & KL_OERR_MASK) { lib3270_ring_bell(hSession); lib3270_write_event_trace(hSession,"typeahead action dropped (operator error)\n"); + errno = EINVAL; return NULL; } @@ -150,6 +153,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { if (hSession->kybdlock & KL_SCROLLED) { lib3270_ring_bell(hSession); lib3270_write_event_trace(hSession,"typeahead action dropped (scrolled)\n"); + errno = EINVAL; return NULL; } @@ -157,6 +161,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { if (!hSession->typeahead) { lib3270_ring_bell(hSession); lib3270_write_event_trace(hSession,"typeahead action dropped (no typeahead)\n"); + errno = EINVAL; return NULL; } diff --git a/src/core/see.c b/src/core/see.c index e2fc858..8d6fa84 100644 --- a/src/core/see.c +++ b/src/core/see.c @@ -180,47 +180,47 @@ const char * see_attr(unsigned char fa) { buf[0] = '\0'; if (fa & FA_PROTECT) { - (void) strcat(buf, paren); - (void) strcat(buf, "protected"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "protected", 255); paren = ","; if (fa & FA_NUMERIC) { - (void) strcat(buf, paren); - (void) strcat(buf, "skip"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "skip", 255); paren = ","; } } else if (fa & FA_NUMERIC) { - (void) strcat(buf, paren); - (void) strcat(buf, "numeric"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "numeric", 255); paren = ","; } switch (fa & FA_INTENSITY) { case FA_INT_NORM_NSEL: break; case FA_INT_NORM_SEL: - (void) strcat(buf, paren); - (void) strcat(buf, "detectable"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "detectable", 255); paren = ","; break; case FA_INT_HIGH_SEL: - (void) strcat(buf, paren); - (void) strcat(buf, "intensified"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "intensified", 255); paren = ","; break; case FA_INT_ZERO_NSEL: - (void) strcat(buf, paren); - (void) strcat(buf, "nondisplay"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "nondisplay", 255); paren = ","; break; } if (fa & FA_MODIFY) { - (void) strcat(buf, paren); - (void) strcat(buf, "modified"); + (void) strncat(buf, paren, 255); + (void) strncat(buf, "modified", 255); paren = ","; } if (strcmp(paren, "(")) - (void) strcat(buf, ")"); + (void) strncat(buf, ")", 255); else - (void) strcpy(buf, "(default)"); + (void) strncpy(buf, "(default)", 255); return buf; } -- libgit2 0.21.2