Date: Thu, 24 Jan 2002 21:58:35 +0200 From: Alexey Zelkin <alexey.zelkin@ionidea.com> To: audit@freebsd.org, ache@freebsd.org Subject: CFR: strncpy -> strlcpy in setlocale() Message-ID: <20020124215835.A58294@gate.sim.ionidea.com>
next in thread | raw e-mail | index | archive | help
hi, Any objections against this patch ? It's based on rev 1.23 of NetBSD's setlocale.c. --- setlocale.c~ Thu Jan 24 18:13:03 2002 +++ setlocale.c Thu Jan 24 21:56:23 2002 @@ -132,33 +132,35 @@ if (!env || !*env || strchr(env, '/')) env = "C"; - (void) strncpy(new_categories[category], env, ENCODING_LEN); - new_categories[category][ENCODING_LEN] = '\0'; + (void)strlcpy(new_categories[category], env, + sizeof(new_categories[category])); if (category == LC_ALL) { for (i = 1; i < _LC_LAST; ++i) { if (!(env = getenv(categories[i])) || !*env) env = new_categories[LC_ALL]; - (void)strncpy(new_categories[i], env, ENCODING_LEN); - new_categories[i][ENCODING_LEN] = '\0'; + (void)strlcpy(new_categories[i], env, + sizeof(new_categories[category])); } } } else if (category != LC_ALL) { - (void)strncpy(new_categories[category], locale, ENCODING_LEN); - new_categories[category][ENCODING_LEN] = '\0'; + (void)strlcpy(new_categories[category], locale, + sizeof(new_categories[category])); } else { if ((r = strchr(locale, '/')) == NULL) { for (i = 1; i < _LC_LAST; ++i) { - (void)strncpy(new_categories[i], locale, ENCODING_LEN); - new_categories[i][ENCODING_LEN] = '\0'; + (void)strlcpy(new_categories[i], locale, + sizeof(new_categories[category])); } } else { - for (i = 1; r[1] == '/'; ++r); + for (i = 1; r[1] == '/'; ++r) + ; if (!r[1]) return (NULL); /* Hmm, just slashes... */ do { - len = r - locale > ENCODING_LEN ? ENCODING_LEN : r - locale; - (void)strncpy(new_categories[i], locale, len); - new_categories[i][len] = '\0'; + len = r - locale > sizeof(new_categories[i]) + ? sizeof(new_categories[i]) + : r - locale; + (void)strlcpy(new_categories[i], locale, len); i++; locale = r; while (*locale == '/') @@ -167,7 +169,7 @@ } while (*locale); while (i < _LC_LAST) { (void)strcpy(new_categories[i], - new_categories[i-1]); + new_categories[i - 1]); i++; } } @@ -201,8 +203,8 @@ for (i = 2; i < _LC_LAST; ++i) if (strcmp(current_categories[1], current_categories[i])) { for (i = 2; i < _LC_LAST; ++i) { - (void) strcat(current_locale_string, "/"); - (void) strcat(current_locale_string, current_categories[i]); + (void)strcat(current_locale_string, "/"); + (void)strcat(current_locale_string, current_categories[i]); } break; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020124215835.A58294>