summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-17 01:29:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-17 01:29:17 +0000
commit22cde7b682328ba195ce0ee214edb6c2feb81b23 (patch)
tree7873fbf3dad59cb2042390c1c2dbfe90d5b6e647 /util.c
parentea9628c3bc700c5162a6298b79d2b8cd7a334fea (diff)
* 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
Diffstat (limited to 'util.c')
-rw-r--r--util.c5
1 files changed, 3 insertions, 2 deletions
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: