From: Klas Lindfors Date: Fri, 20 Dec 2013 09:11:12 +0000 (+0100) Subject: use strncat to build the option strings for printing X-Git-Tag: v1.14.2~4 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea06ab51356f038ea07274dcdd473ee27f865f3;p=yubikey-personalization use strncat to build the option strings for printing slightly simpler code --- diff --git a/ykpers.c b/ykpers.c index df6f29f..51108f4 100644 --- a/ykpers.c +++ b/ykpers.c @@ -987,11 +987,9 @@ static int _ykp_legacy_export_config(const YKP_CONFIG *cfg, char *buf, size_t le && p->capability(cfg) && (mode & p->mode) == mode) { if (*buffer) { - strcat(buffer, str_flags_separator); - strcat(buffer, p->flag_text); - } else { - strcpy(buffer, p->flag_text); + strncat(buffer, str_flags_separator, 256 - strlen(buffer)); } + strncat(buffer, p->flag_text, 256 - strlen(buffer)); } } pos += snprintf(buf + pos, len - (size_t)pos, "%s%s%s\n", str_ticket_flags, str_key_value_separator, buffer); @@ -1004,11 +1002,9 @@ static int _ykp_legacy_export_config(const YKP_CONFIG *cfg, char *buf, size_t le && p->capability(cfg) && (mode & p->mode) == mode) { if (*buffer) { - strcat(buffer, str_flags_separator); - strcat(buffer, p->flag_text); - } else { - strcpy(buffer, p->flag_text); + strncat(buffer, str_flags_separator, 256 - strlen(buffer)); } + strncat(buffer, p->flag_text, 256 - strlen(buffer)); /* make sure we don't show more than one cfgFlag per value - some cfgflags share value in different contexts */ @@ -1024,11 +1020,9 @@ static int _ykp_legacy_export_config(const YKP_CONFIG *cfg, char *buf, size_t le && p->capability(cfg) && (mode & p->mode) == mode) { if (*buffer) { - strcat(buffer, str_flags_separator); - strcat(buffer, p->flag_text); - } else { - strcpy(buffer, p->flag_text); + strncat(buffer, str_flags_separator, 256 - strlen(buffer)); } + strncat(buffer, p->flag_text, 256 - strlen(buffer)); } } pos += snprintf(buf + pos, len - (size_t)pos, "%s%s%s\n", str_extended_flags, str_key_value_separator, buffer);