Commit c24fe1f7e8b2bc8169e994172a0704e06f53aed4

Authored by Perry Werneck
1 parent 0b997e22
Exists in master and in 1 other branch develop

Fixing some CodeQL alerts.

src/core/ansi.c
@@ -1729,7 +1729,7 @@ ansi_send_pf(H3270 *hSession, int nn) { @@ -1729,7 +1729,7 @@ ansi_send_pf(H3270 *hSession, int nn) {
1729 1729
1730 if (nn < 1 || ((size_t) nn) > sizeof(code)/sizeof(code[0])) 1730 if (nn < 1 || ((size_t) nn) > sizeof(code)/sizeof(code[0]))
1731 return; 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 net_sends(hSession,fn_buf); 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,7 +90,8 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u
90 status_reset(hSession); 90 status_reset(hSession);
91 } else { 91 } else {
92 struct ta *ta = new_ta(hSession, TA_TYPE_CURSOR_MOVE); 92 struct ta *ta = new_ta(hSession, TA_TYPE_CURSOR_MOVE);
93 - 93 + if(!ta)
  94 + return -1;
94 ta->args.move.direction = dir; 95 ta->args.move.direction = dir;
95 ta->args.move.fn = lib3270_move_cursor; 96 ta->args.move.fn = lib3270_move_cursor;
96 ta->args.move.sel = sel; 97 ta->args.move.sel = sel;
src/core/keyboard/kybd.c
@@ -128,14 +128,16 @@ static const char dxl[] = &quot;0123456789abcdef&quot;; @@ -128,14 +128,16 @@ static const char dxl[] = &quot;0123456789abcdef&quot;;
128 * Check for typeahead availability and create a new TA structure. 128 * Check for typeahead availability and create a new TA structure.
129 * 129 *
130 * @return new typeahead struct or NULL if it's not available. 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 struct ta * new_ta(H3270 *hSession, enum _ta_type type) { 133 struct ta * new_ta(H3270 *hSession, enum _ta_type type) {
133 - struct ta *ta; 134 + struct ta *ta = NULL;
134 135
135 // If no connection, forget it. 136 // If no connection, forget it.
136 if (!lib3270_is_connected(hSession)) { 137 if (!lib3270_is_connected(hSession)) {
137 lib3270_ring_bell(hSession); 138 lib3270_ring_bell(hSession);
138 lib3270_write_event_trace(hSession,"typeahead action dropped (not connected)\n"); 139 lib3270_write_event_trace(hSession,"typeahead action dropped (not connected)\n");
  140 + errno = ENOTCONN;
139 return NULL; 141 return NULL;
140 } 142 }
141 143
@@ -143,6 +145,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { @@ -143,6 +145,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) {
143 if (hSession->kybdlock & KL_OERR_MASK) { 145 if (hSession->kybdlock & KL_OERR_MASK) {
144 lib3270_ring_bell(hSession); 146 lib3270_ring_bell(hSession);
145 lib3270_write_event_trace(hSession,"typeahead action dropped (operator error)\n"); 147 lib3270_write_event_trace(hSession,"typeahead action dropped (operator error)\n");
  148 + errno = EINVAL;
146 return NULL; 149 return NULL;
147 } 150 }
148 151
@@ -150,6 +153,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { @@ -150,6 +153,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) {
150 if (hSession->kybdlock & KL_SCROLLED) { 153 if (hSession->kybdlock & KL_SCROLLED) {
151 lib3270_ring_bell(hSession); 154 lib3270_ring_bell(hSession);
152 lib3270_write_event_trace(hSession,"typeahead action dropped (scrolled)\n"); 155 lib3270_write_event_trace(hSession,"typeahead action dropped (scrolled)\n");
  156 + errno = EINVAL;
153 return NULL; 157 return NULL;
154 } 158 }
155 159
@@ -157,6 +161,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) { @@ -157,6 +161,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) {
157 if (!hSession->typeahead) { 161 if (!hSession->typeahead) {
158 lib3270_ring_bell(hSession); 162 lib3270_ring_bell(hSession);
159 lib3270_write_event_trace(hSession,"typeahead action dropped (no typeahead)\n"); 163 lib3270_write_event_trace(hSession,"typeahead action dropped (no typeahead)\n");
  164 + errno = EINVAL;
160 return NULL; 165 return NULL;
161 } 166 }
162 167
src/core/see.c
@@ -180,47 +180,47 @@ const char * see_attr(unsigned char fa) { @@ -180,47 +180,47 @@ const char * see_attr(unsigned char fa) {
180 buf[0] = '\0'; 180 buf[0] = '\0';
181 181
182 if (fa & FA_PROTECT) { 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 paren = ","; 185 paren = ",";
186 if (fa & FA_NUMERIC) { 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 paren = ","; 189 paren = ",";
190 } 190 }
191 } else if (fa & FA_NUMERIC) { 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 paren = ","; 194 paren = ",";
195 } 195 }
196 switch (fa & FA_INTENSITY) { 196 switch (fa & FA_INTENSITY) {
197 case FA_INT_NORM_NSEL: 197 case FA_INT_NORM_NSEL:
198 break; 198 break;
199 case FA_INT_NORM_SEL: 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 paren = ","; 202 paren = ",";
203 break; 203 break;
204 case FA_INT_HIGH_SEL: 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 paren = ","; 207 paren = ",";
208 break; 208 break;
209 case FA_INT_ZERO_NSEL: 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 paren = ","; 212 paren = ",";
213 break; 213 break;
214 } 214 }
215 if (fa & FA_MODIFY) { 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 paren = ","; 218 paren = ",";
219 } 219 }
220 if (strcmp(paren, "(")) 220 if (strcmp(paren, "("))
221 - (void) strcat(buf, ")"); 221 + (void) strncat(buf, ")", 255);
222 else 222 else
223 - (void) strcpy(buf, "(default)"); 223 + (void) strncpy(buf, "(default)", 255);
224 224
225 return buf; 225 return buf;
226 } 226 }