Commit c24fe1f7e8b2bc8169e994172a0704e06f53aed4
1 parent
0b997e22
Exists in
master
and in
1 other branch
Fixing some CodeQL alerts.
Showing
4 changed files
with
25 additions
and
19 deletions
Show diff stats
src/core/ansi.c
| ... | ... | @@ -1729,7 +1729,7 @@ ansi_send_pf(H3270 *hSession, int nn) { |
| 1729 | 1729 | |
| 1730 | 1730 | if (nn < 1 || ((size_t) nn) > sizeof(code)/sizeof(code[0])) |
| 1731 | 1731 | return; |
| 1732 | - (void) sprintf(fn_buf, ", "\033[%d~", code[nn-1]);33[%d~", code[nn-1]); | |
| 1732 | + (void) snprintf(fn_buf, sizeof(fn_buf), ", "\033[%d~", code[nn-1]);33[%d~", code[nn-1]); | |
| 1733 | 1733 | net_sends(hSession,fn_buf); |
| 1734 | 1734 | } |
| 1735 | 1735 | ... | ... |
src/core/cursor.c
| ... | ... | @@ -90,7 +90,8 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u |
| 90 | 90 | status_reset(hSession); |
| 91 | 91 | } else { |
| 92 | 92 | struct ta *ta = new_ta(hSession, TA_TYPE_CURSOR_MOVE); |
| 93 | - | |
| 93 | + if(!ta) | |
| 94 | + return -1; | |
| 94 | 95 | ta->args.move.direction = dir; |
| 95 | 96 | ta->args.move.fn = lib3270_move_cursor; |
| 96 | 97 | ta->args.move.sel = sel; | ... | ... |
src/core/keyboard/kybd.c
| ... | ... | @@ -128,14 +128,16 @@ static const char dxl[] = "0123456789abcdef"; |
| 128 | 128 | * Check for typeahead availability and create a new TA structure. |
| 129 | 129 | * |
| 130 | 130 | * @return new typeahead struct or NULL if it's not available. |
| 131 | + * @retval NULL Host is not connected or malloc error. | |
| 131 | 132 | */ |
| 132 | 133 | struct ta * new_ta(H3270 *hSession, enum _ta_type type) { |
| 133 | - struct ta *ta; | |
| 134 | + struct ta *ta = NULL; | |
| 134 | 135 | |
| 135 | 136 | // If no connection, forget it. |
| 136 | 137 | if (!lib3270_is_connected(hSession)) { |
| 137 | 138 | lib3270_ring_bell(hSession); |
| 138 | 139 | lib3270_write_event_trace(hSession,"typeahead action dropped (not connected)\n"); |
| 140 | + errno = ENOTCONN; | |
| 139 | 141 | return NULL; |
| 140 | 142 | } |
| 141 | 143 | |
| ... | ... | @@ -143,6 +145,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { |
| 143 | 145 | if (hSession->kybdlock & KL_OERR_MASK) { |
| 144 | 146 | lib3270_ring_bell(hSession); |
| 145 | 147 | lib3270_write_event_trace(hSession,"typeahead action dropped (operator error)\n"); |
| 148 | + errno = EINVAL; | |
| 146 | 149 | return NULL; |
| 147 | 150 | } |
| 148 | 151 | |
| ... | ... | @@ -150,6 +153,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { |
| 150 | 153 | if (hSession->kybdlock & KL_SCROLLED) { |
| 151 | 154 | lib3270_ring_bell(hSession); |
| 152 | 155 | lib3270_write_event_trace(hSession,"typeahead action dropped (scrolled)\n"); |
| 156 | + errno = EINVAL; | |
| 153 | 157 | return NULL; |
| 154 | 158 | } |
| 155 | 159 | |
| ... | ... | @@ -157,6 +161,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { |
| 157 | 161 | if (!hSession->typeahead) { |
| 158 | 162 | lib3270_ring_bell(hSession); |
| 159 | 163 | lib3270_write_event_trace(hSession,"typeahead action dropped (no typeahead)\n"); |
| 164 | + errno = EINVAL; | |
| 160 | 165 | return NULL; |
| 161 | 166 | } |
| 162 | 167 | ... | ... |
src/core/see.c
| ... | ... | @@ -180,47 +180,47 @@ const char * see_attr(unsigned char fa) { |
| 180 | 180 | buf[0] = '\0'; |
| 181 | 181 | |
| 182 | 182 | if (fa & FA_PROTECT) { |
| 183 | - (void) strcat(buf, paren); | |
| 184 | - (void) strcat(buf, "protected"); | |
| 183 | + (void) strncat(buf, paren, 255); | |
| 184 | + (void) strncat(buf, "protected", 255); | |
| 185 | 185 | paren = ","; |
| 186 | 186 | if (fa & FA_NUMERIC) { |
| 187 | - (void) strcat(buf, paren); | |
| 188 | - (void) strcat(buf, "skip"); | |
| 187 | + (void) strncat(buf, paren, 255); | |
| 188 | + (void) strncat(buf, "skip", 255); | |
| 189 | 189 | paren = ","; |
| 190 | 190 | } |
| 191 | 191 | } else if (fa & FA_NUMERIC) { |
| 192 | - (void) strcat(buf, paren); | |
| 193 | - (void) strcat(buf, "numeric"); | |
| 192 | + (void) strncat(buf, paren, 255); | |
| 193 | + (void) strncat(buf, "numeric", 255); | |
| 194 | 194 | paren = ","; |
| 195 | 195 | } |
| 196 | 196 | switch (fa & FA_INTENSITY) { |
| 197 | 197 | case FA_INT_NORM_NSEL: |
| 198 | 198 | break; |
| 199 | 199 | case FA_INT_NORM_SEL: |
| 200 | - (void) strcat(buf, paren); | |
| 201 | - (void) strcat(buf, "detectable"); | |
| 200 | + (void) strncat(buf, paren, 255); | |
| 201 | + (void) strncat(buf, "detectable", 255); | |
| 202 | 202 | paren = ","; |
| 203 | 203 | break; |
| 204 | 204 | case FA_INT_HIGH_SEL: |
| 205 | - (void) strcat(buf, paren); | |
| 206 | - (void) strcat(buf, "intensified"); | |
| 205 | + (void) strncat(buf, paren, 255); | |
| 206 | + (void) strncat(buf, "intensified", 255); | |
| 207 | 207 | paren = ","; |
| 208 | 208 | break; |
| 209 | 209 | case FA_INT_ZERO_NSEL: |
| 210 | - (void) strcat(buf, paren); | |
| 211 | - (void) strcat(buf, "nondisplay"); | |
| 210 | + (void) strncat(buf, paren, 255); | |
| 211 | + (void) strncat(buf, "nondisplay", 255); | |
| 212 | 212 | paren = ","; |
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | if (fa & FA_MODIFY) { |
| 216 | - (void) strcat(buf, paren); | |
| 217 | - (void) strcat(buf, "modified"); | |
| 216 | + (void) strncat(buf, paren, 255); | |
| 217 | + (void) strncat(buf, "modified", 255); | |
| 218 | 218 | paren = ","; |
| 219 | 219 | } |
| 220 | 220 | if (strcmp(paren, "(")) |
| 221 | - (void) strcat(buf, ")"); | |
| 221 | + (void) strncat(buf, ")", 255); | |
| 222 | 222 | else |
| 223 | - (void) strcpy(buf, "(default)"); | |
| 223 | + (void) strncpy(buf, "(default)", 255); | |
| 224 | 224 | |
| 225 | 225 | return buf; |
| 226 | 226 | } | ... | ... |