From 1e7328ef6f161ec69d0db20ec62522f276a90208 Mon Sep 17 00:00:00 2001 From: John Jenkins Date: Wed, 16 Sep 2015 11:19:47 -0500 Subject: [PATCH] use strcpy in codes_mapping_get_lp_info strncpy might prevent bad internal state from destroying everything, but it also writes MAX_NAME_LENGTH bytes unconditionally, clobbering input if it isn't long enough. Besides, internal state will only be inconsistent if people are trying to call codes_mapping_get_lp_info without configuring in the first place... --- src/util/codes_mapping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/codes_mapping.c b/src/util/codes_mapping.c index bdd79b8..90e8f4a 100644 --- a/src/util/codes_mapping.c +++ b/src/util/codes_mapping.c @@ -359,7 +359,7 @@ void codes_mapping_get_lp_info( // we've found the group tw_lpid rem = gid - id_total; if (group_name != NULL) - strncpy(group_name, lpg->name.ptr, MAX_NAME_LENGTH); + strcpy(group_name, lpg->name.ptr); *group_index = g; // find repetition within group *rep_id = (int) (rem / num_id_per_rep); @@ -370,12 +370,12 @@ void codes_mapping_get_lp_info( if (rem < num_id_per_rep + lpt->count){ // found the specific LP if (lp_type_name != NULL) - strncpy(lp_type_name, lpt->name.ptr, MAX_NAME_LENGTH); + strcpy(lp_type_name, lpt->name.ptr); if (annotation != NULL) { if (lpt->anno.ptr == NULL) annotation[0] = '\0'; else - strncpy(annotation, lpt->anno.ptr, MAX_NAME_LENGTH); + strcpy(annotation, lpt->anno.ptr); } *offset = (int) (rem - num_id_per_rep); *lp_type_index = l; -- 2.26.2