Skip to content

Commit

Permalink
Use strncpy
Browse files Browse the repository at this point in the history
  • Loading branch information
rs22 committed Jan 5, 2024
1 parent 38e412e commit 8e4d313
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/common/c/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,21 +662,24 @@ void config_setstd(struct RastaConfig *cfg) {
cfg->values.tls.ca_cert_path = NULL;
if (entr.type == DICTIONARY_STRING) {
cfg->values.tls.ca_cert_path = malloc(MAX_DICTIONARY_STRING_LENGTH_BYTES);
strcpy(cfg->values.tls.ca_cert_path, entr.value.string.c);
strncpy(cfg->values.tls.ca_cert_path, entr.value.string.c, MAX_DICTIONARY_STRING_LENGTH_BYTES);
cfg->values.tls.ca_cert_path[MAX_DICTIONARY_STRING_LENGTH_BYTES] = '\0';
}

entr = config_get(cfg, "RASTA_CERT_PATH");
cfg->values.tls.cert_path = NULL;
if (entr.type == DICTIONARY_STRING) {
cfg->values.tls.cert_path = malloc(MAX_DICTIONARY_STRING_LENGTH_BYTES);
strcpy(cfg->values.tls.cert_path, entr.value.string.c);
strncpy(cfg->values.tls.cert_path, entr.value.string.c, MAX_DICTIONARY_STRING_LENGTH_BYTES);
cfg->values.tls.cert_path[MAX_DICTIONARY_STRING_LENGTH_BYTES] = '\0';
}

entr = config_get(cfg, "RASTA_KEY_PATH");
cfg->values.tls.key_path = NULL;
if (entr.type == DICTIONARY_STRING) {
cfg->values.tls.key_path = malloc(MAX_DICTIONARY_STRING_LENGTH_BYTES);
strcpy(cfg->values.tls.key_path, entr.value.string.c);
strncpy(cfg->values.tls.key_path, entr.value.string.c, MAX_DICTIONARY_STRING_LENGTH_BYTES);
cfg->values.tls.key_path[MAX_DICTIONARY_STRING_LENGTH_BYTES] = '\0';
}

#ifdef ENABLE_TLS
Expand All @@ -689,7 +692,8 @@ void config_setstd(struct RastaConfig *cfg) {
cfg->values.tls.peer_tls_cert_path = NULL;
if (entr.type == DICTIONARY_STRING) {
cfg->values.tls.peer_tls_cert_path = malloc(MAX_DICTIONARY_STRING_LENGTH_BYTES);
strcpy(cfg->values.tls.peer_tls_cert_path, entr.value.string.c);
strncpy(cfg->values.tls.peer_tls_cert_path, entr.value.string.c, MAX_DICTIONARY_STRING_LENGTH_BYTES);
cfg->values.tls.peer_tls_cert_path[MAX_DICTIONARY_STRING_LENGTH_BYTES] = '\0';
}
#endif

Expand Down

0 comments on commit 8e4d313

Please sign in to comment.