From 22cde7b682328ba195ce0ee214edb6c2feb81b23 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 17 Mar 2009 01:29:17 +0000 Subject: * dir.c, dln.c, parse.y, re.c, ruby.c, sprintf.c, strftime.c, string.c, util.c, variable.c: use strlcpy, memcpy and snprintf instead of strcpy, strncpy and sprintf. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index fad309cb1f..bb4a63bc9b 100644 --- a/util.c +++ b/util.c @@ -270,6 +270,7 @@ ruby_add_suffix(VALUE str, const char *suffix) char *s, *t, *p; long slen; char buf[1024]; + char *const bufend = buf + sizeof(buf); if (RSTRING_LEN(str) > 1000) rb_fatal("Cannot do inplace edit on long filename (%ld characters)", @@ -300,7 +301,7 @@ ruby_add_suffix(VALUE str, const char *suffix) if (*suffix == '.') { /* Style 1 */ if (strEQ(ext, suffix)) goto fallback; - strcpy(p, suffix); + strlcpy(p, suffix, bufend - p); } else if (suffix[1] == '\0') { /* Style 2 */ if (extlen < 4) { @@ -317,7 +318,7 @@ ruby_add_suffix(VALUE str, const char *suffix) buf[7] = *suffix; } else goto fallback; - strcpy(p, ext); + strlcpy(p, ext, bufend - p); } else { /* Style 3: Panic */ fallback: -- cgit v1.2.3