diff options
-rw-r--r-- | lib/str.c | 2 | ||||
-rw-r--r-- | src/certtool-cfg.c | 10 |
2 files changed, 9 insertions, 3 deletions
@@ -60,7 +60,7 @@ void _gnutls_str_cpy(char *dest, size_t dest_tot_size, const char *src) strcpy(dest, src); } else { if (dest_tot_size > 0) { - strncpy(dest, src, (dest_tot_size) - 1); + memcpy(dest, src, (dest_tot_size) - 1); dest[dest_tot_size - 1] = 0; } } diff --git a/src/certtool-cfg.c b/src/certtool-cfg.c index 722dbee6d8..d149021bcb 100644 --- a/src/certtool-cfg.c +++ b/src/certtool-cfg.c @@ -254,14 +254,20 @@ void cfg_init(void) { \ char str[512]; \ char * p; \ + int len; \ if (s_name == NULL) { \ i = 0; \ s_name = malloc(sizeof(char*)*MAX_ENTRIES); \ do { \ if (val && !strcmp(val->pzName, name)==0) \ continue; \ - strncpy(str, val->v.strVal, sizeof(str)-1); \ - str[sizeof(str)-1] = 0; \ + len = strlen(val->v.strVal); \ + if (sizeof(str) > len) { \ + strcpy(str, val->v.strVal); \ + } else { \ + memcpy(str, val->v.strVal, sizeof(str)-1); \ + str[sizeof(str)-1] = 0; \ + } \ if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \ fprintf(stderr, "Error parsing %s\n", name); \ exit(1); \ |