summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-30 02:50:58 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-30 02:50:58 +0000
commit528e8517b8ed545ecd8aef678ec542275f08c8f7 (patch)
treed9bfc61d5120d2f6af34e7dc2c5fece944e08757
parenta2dba5be2dc43f69635e1c71482802428e973ec6 (diff)
* win32/win32.c (rb_w32_cmdvector): fixed buffer size. reported by
wanabe [ruby-dev:30672] * win32/win32.c (init_env, insert, rb_w32_get_environ): use strdup instead of malloc + strlcpy. suggested by nobu [ruby-dev:30673] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--win32/win32.c15
2 files changed, 13 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 16ddc87fe9..8cb084df35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Mar 30 11:46:51 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (rb_w32_cmdvector): fixed buffer size. reported by
+ wanabe [ruby-dev:30672]
+
+ * win32/win32.c (init_env, insert, rb_w32_get_environ): use strdup
+ instead of malloc + strlcpy. suggested by nobu [ruby-dev:30673]
+
Fri Mar 30 02:29:04 2007 Technorama <oss-ruby@technorama.net>
* ext/openssl/ossl_{bn,cipher,digest,hmac,rand,pkey_{dh,dsa,rsa}}.c:
diff --git a/win32/win32.c b/win32/win32.c
index 535a6b06ff..823ced33f1 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -401,10 +401,7 @@ init_env(void)
NTLoginName = "<Unknown>";
return;
}
- NTLoginName = (char *)malloc(len+1);
- if (!NTLoginName) return;
- strlcpy(NTLoginName, env, len + 1);
- NTLoginName[len] = '\0';
+ NTLoginName = strdup(env);
}
static void init_stdhandle(void);
@@ -1056,10 +1053,9 @@ insert(const char *path, VALUE vinfo)
if (!tmpcurr) return -1;
MEMZERO(tmpcurr, NtCmdLineElement, 1);
tmpcurr->len = strlen(path);
- tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
+ tmpcurr->str = strdup(path);
if (!tmpcurr->str) return -1;
tmpcurr->flags |= NTMALLOC;
- strlcpy(tmpcurr->str, path, tmpcurr->len + 1);
**tail = tmpcurr;
*tail = &tmpcurr->next;
@@ -1373,7 +1369,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
ptr = buffer + (elements+1) * sizeof(char *);
while (curr = cmdhead) {
- strlcpy(ptr, curr->str, len - (elements + 1));
+ strlcpy(ptr, curr->str, curr->len + 1);
*vptr++ = ptr;
ptr += curr->len + 1;
cmdhead = curr->next;
@@ -1861,7 +1857,7 @@ rb_w32_strerror(int e)
e = GetLastError();
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
- buffer, 512, NULL) == 0)
+ buffer, sizeof(buffer), NULL) == 0)
strlcpy(buffer, "Unknown Error", sizeof(buffer));
}
else
@@ -3916,10 +3912,9 @@ rb_w32_get_environ(void)
for (env = envtop, myenv = myenvtop; *env; env += strlen(env) + 1) {
if (*env != '=') {
int len = strlen(env) + 1;
- if (!(*myenv = (char *)malloc(len))) {
+ if (!(*myenv = strdup(env))) {
break;
}
- strlcpy(*myenv, env, len);
myenv++;
}
}