Commit d04b76ae7ac7cf2de13107b5bea6b376564e4c8d
1 parent
2fb545f7
Exists in
master
and in
3 other branches
Fixing segfault.
Showing
3 changed files
with
19 additions
and
2 deletions
Show diff stats
src/core/array.c
| ... | ... | @@ -61,7 +61,7 @@ void lib3270_string_array_free(LIB3270_STRING_ARRAY *array) |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | -void lib3270_string_array_append(LIB3270_STRING_ARRAY *array, const char *str) | |
| 64 | +static void lib3270_string_array_realloc(LIB3270_STRING_ARRAY *array) | |
| 65 | 65 | { |
| 66 | 66 | if(array->str) |
| 67 | 67 | { |
| ... | ... | @@ -73,8 +73,23 @@ void lib3270_string_array_append(LIB3270_STRING_ARRAY *array, const char *str) |
| 73 | 73 | array->length = 0; // Just in case. |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | +} | |
| 77 | + | |
| 78 | +void lib3270_string_array_append(LIB3270_STRING_ARRAY *array, const char *str) | |
| 79 | +{ | |
| 80 | + lib3270_string_array_realloc(array); | |
| 76 | 81 | array->str[array->length++] = strdup(str); |
| 82 | +} | |
| 83 | + | |
| 84 | +void lib3270_string_array_append_with_length(LIB3270_STRING_ARRAY *array, const char *str, size_t length) | |
| 85 | +{ | |
| 86 | + lib3270_string_array_realloc(array); | |
| 87 | + | |
| 88 | + char * buffer = lib3270_malloc(length+1); | |
| 89 | + memcpy(buffer,str,length); | |
| 90 | + buffer[length] = 0; | |
| 77 | 91 | |
| 92 | + array->str[array->length++] = buffer; | |
| 78 | 93 | } |
| 79 | 94 | |
| 80 | 95 | void lib3270_autoptr_cleanup_LIB3270_STRING_ARRAY(LIB3270_STRING_ARRAY **ptr) | ... | ... |
src/include/array.h
| ... | ... | @@ -48,6 +48,8 @@ |
| 48 | 48 | LIB3270_INTERNAL LIB3270_STRING_ARRAY * lib3270_string_array_new(void); |
| 49 | 49 | LIB3270_INTERNAL void lib3270_string_array_free(LIB3270_STRING_ARRAY *object); |
| 50 | 50 | LIB3270_INTERNAL void lib3270_string_array_append(LIB3270_STRING_ARRAY *object, const char *str); |
| 51 | + LIB3270_INTERNAL void lib3270_string_array_append_with_length(LIB3270_STRING_ARRAY *array, const char *str, size_t length); | |
| 52 | + | |
| 51 | 53 | LIB3270_INTERNAL void lib3270_autoptr_cleanup_LIB3270_STRING_ARRAY(LIB3270_STRING_ARRAY **ptr); |
| 52 | 54 | |
| 53 | 55 | #endif // LIB3270_ARRAY_H_INCLUDED | ... | ... |
src/ssl/crl.c
| ... | ... | @@ -205,7 +205,7 @@ int lib3270_crl_new_from_dist_points(H3270 *hSession, void *ssl_error, CRL_DIST_ |
| 205 | 205 | #endif // OpenSSL 1.1.0+ |
| 206 | 206 | if(data) |
| 207 | 207 | { |
| 208 | - lib3270_string_array_append(uris,(char *) data); | |
| 208 | + lib3270_string_array_append_with_length(uris,(char *) data, (size_t) ASN1_STRING_length(uri)); | |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | ... | ... |