From 365cbb61be9764e35b820889f2f3206c6c1714f4 Mon Sep 17 00:00:00 2001 From: witekfl Date: Sun, 19 Sep 2010 15:16:00 +0200 Subject: [PATCH] strcpy -> strlcpy. Some of these changes doesn't make sense, but warnings are avoided. --- src/intl/gettext/libintl.c | 10 ++++++---- src/intl/gettext/libintl.h | 7 +++---- src/intl/gettext/localcharset.c | 6 +++--- src/protocol/uri.c | 6 ++++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/intl/gettext/libintl.c b/src/intl/gettext/libintl.c index cde480d4..714c059b 100644 --- a/src/intl/gettext/libintl.c +++ b/src/intl/gettext/libintl.c @@ -206,10 +206,12 @@ set_language(int language) /* We never free() this, purely intentionally. */ LANGUAGE = malloc(256); } - strcpy(LANGUAGE, language_to_iso639(language)); - p = strchr(LANGUAGE, '-'); - if (p) - *p = '_'; + if (LANGUAGE) { + strlcpy(LANGUAGE, language_to_iso639(language), 256); + p = strchr(LANGUAGE, '-'); + if (p) + *p = '_'; + } /* Propagate the change to gettext. From the info manual. */ { diff --git a/src/intl/gettext/libintl.h b/src/intl/gettext/libintl.h index 15d6804b..ee4b92f3 100644 --- a/src/intl/gettext/libintl.h +++ b/src/intl/gettext/libintl.h @@ -142,10 +142,9 @@ __(unsigned char *file, unsigned int line, unsigned char *func, file, line, func, last_line); } - /* Risky ;) */ - strcpy(last_file, file); - strcpy(last_func, func); - strcpy(last_result, result); + strlcpy(last_file, file, 512); + strlcpy(last_func, func, 1024); + strlcpy(last_result, result, 16384); last_line = line; return result; diff --git a/src/intl/gettext/localcharset.c b/src/intl/gettext/localcharset.c index 207f3364..b3578312 100644 --- a/src/intl/gettext/localcharset.c +++ b/src/intl/gettext/localcharset.c @@ -155,9 +155,9 @@ get_charset_aliases(void) res_size = 0; break; } - strcpy(res_ptr + res_size - (l2 + 1) - (l1 + 1), - buf1); - strcpy(res_ptr + res_size - (l2 + 1), buf2); + strlcpy(res_ptr + res_size - (l2 + 1) - (l1 + 1), + buf1, l1 + 1 + l2 + 1 + 1); + strlcpy(res_ptr + res_size - (l2 + 1), buf2, l2 + 1); } fclose(fp); if (res_size == 0) diff --git a/src/protocol/uri.c b/src/protocol/uri.c index 5e23ea27..9bd810a8 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -874,6 +874,7 @@ join_urls(struct uri *base, unsigned char *rel) int add_slash = 0; int translate = 0; int length = 0; + int rel_len; /* See RFC 1808 */ /* TODO: Support for ';' ? (see the RFC) --pasky */ @@ -988,12 +989,13 @@ join_urls(struct uri *base, unsigned char *rel) } length = path - struri(base); - uristring = mem_alloc(length + strlen(rel) + add_slash + 1); + rel_len = strlen(rel); + uristring = mem_alloc(length + rel_len + add_slash + 1); if (!uristring) return NULL; memcpy(uristring, struri(base), length); if (add_slash) uristring[length] = '/'; - strcpy(uristring + length + add_slash, rel); + strlcpy(uristring + length + add_slash, rel, rel_len + 1); return normalize_uri_reparse(uristring); }