summaryrefslogtreecommitdiffstats
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
commit68fb85a36ad39d5594c1ecfbf985d56e73adcaa5 (patch)
tree7873fbf3dad59cb2042390c1c2dbfe90d5b6e647 /util.c
parent61618d9b634c10e93dcb2496b2955581cf4871e4 (diff)
downloadruby-68fb85a36ad39d5594c1ecfbf985d56e73adcaa5.tar.gz
ruby-68fb85a36ad39d5594c1ecfbf985d56e73adcaa5.tar.xz
ruby-68fb85a36ad39d5594c1ecfbf985d56e73adcaa5.zip
* 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: http://svn.ruby-lang.org/repos/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 fad309cb1..bb4a63bc9 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: