diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-25 00:08:06 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-25 00:08:06 +0000 |
commit | 0506348ef501d5f2e3dc64666b6bb6785870583c (patch) | |
tree | 016b438062d2f2c3680cb5892153ee7166959c20 | |
parent | 940e021edce66ff9760f57148a813f1dff357d9f (diff) | |
download | ruby-0506348ef501d5f2e3dc64666b6bb6785870583c.tar.gz |
* dir.c (join_path): use strlcat() to force link.
* dir.c (glob_helper): no strcpy() is needed since len is known.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | dir.c | 14 |
2 files changed, 14 insertions, 6 deletions
@@ -1,3 +1,9 @@ +Sun Jan 25 09:09:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * dir.c (join_path): use strlcat() to force link. + + * dir.c (glob_helper): no strcpy() is needed since len is known. + Sun Jan 25 06:44:58 2009 Technorama Ltd. <oss-ruby@technorama.net> * ext/openssl/ossl_ssl.c: Server Name Indication support. @@ -1112,15 +1112,16 @@ static char * join_path(const char *path, int dirsep, const char *name) { long len = strlen(path); - char *buf = GLOB_ALLOC_N(char, len+strlen(name)+(dirsep?1:0)+1); + long len2 = strlen(name)+(dirsep?1:0)+1; + char *buf = GLOB_ALLOC_N(char, len+len2); if (!buf) return 0; memcpy(buf, path, len); if (dirsep) { - strcpy(buf+len, "/"); - len++; + buf[len++] = '/'; } - strcpy(buf+len, name); + buf[len] = '\0'; + strlcat(buf+len, name, len2); return buf; } @@ -1301,12 +1302,13 @@ glob_helper( if (*cur) { char *buf; char *name; - name = GLOB_ALLOC_N(char, strlen((*cur)->str) + 1); + size_t len = strlen((*cur)->str) + 1; + name = GLOB_ALLOC_N(char, len); if (!name) { status = -1; break; } - strcpy(name, (*cur)->str); + memcpy(name, (*cur)->str, len); if (escape) remove_backslashes(name, enc); new_beg = new_end = GLOB_ALLOC_N(struct glob_pattern *, end - beg); |