* win32/win32.c (init_env, insert, cmdglob, rb_w32_cmdvector,
rb_w32_opendir, rb_w32_readdir, rb_w32_strerror, rb_w32_stati64, rb_w32_get_environ): use strlcpy() and strlcat(). * win32/win32.c (rb_w32_opendir): use realloc() instead of xrealloc(). * win32/win32.c (rb_w32_closedir): check NULL before free pointers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69b8b645b5
commit
240f1279aa
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Fri Mar 23 11:28:24 2007 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (init_env, insert, cmdglob, rb_w32_cmdvector,
|
||||||
|
rb_w32_opendir, rb_w32_readdir, rb_w32_strerror, rb_w32_stati64,
|
||||||
|
rb_w32_get_environ): use strlcpy() and strlcat().
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_opendir): use realloc() instead of xrealloc().
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_closedir): check NULL before free pointers.
|
||||||
|
|
||||||
Fri Mar 23 00:24:52 2007 Keiju Ishitsuka <keiju@ruby-lang.org>
|
Fri Mar 23 00:24:52 2007 Keiju Ishitsuka <keiju@ruby-lang.org>
|
||||||
|
|
||||||
* lib/shell: commit miss(support for ruby 1.9(YARV) thread model).
|
* lib/shell: commit miss(support for ruby 1.9(YARV) thread model).
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2007-03-22"
|
#define RUBY_RELEASE_DATE "2007-03-23"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20070322
|
#define RUBY_RELEASE_CODE 20070323
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 3
|
#define RUBY_RELEASE_MONTH 3
|
||||||
#define RUBY_RELEASE_DAY 22
|
#define RUBY_RELEASE_DAY 23
|
||||||
|
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
RUBY_EXTERN const char ruby_release_date[];
|
RUBY_EXTERN const char ruby_release_date[];
|
||||||
|
@ -403,7 +403,7 @@ init_env(void)
|
|||||||
}
|
}
|
||||||
NTLoginName = (char *)malloc(len+1);
|
NTLoginName = (char *)malloc(len+1);
|
||||||
if (!NTLoginName) return;
|
if (!NTLoginName) return;
|
||||||
strncpy(NTLoginName, env, len);
|
strlcpy(NTLoginName, env, len + 1);
|
||||||
NTLoginName[len] = '\0';
|
NTLoginName[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,7 +1059,7 @@ insert(const char *path, VALUE vinfo)
|
|||||||
tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
|
tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
|
||||||
if (!tmpcurr->str) return -1;
|
if (!tmpcurr->str) return -1;
|
||||||
tmpcurr->flags |= NTMALLOC;
|
tmpcurr->flags |= NTMALLOC;
|
||||||
strcpy(tmpcurr->str, path);
|
strlcpy(tmpcurr->str, path, tmpcurr->len + 1);
|
||||||
**tail = tmpcurr;
|
**tail = tmpcurr;
|
||||||
*tail = &tmpcurr->next;
|
*tail = &tmpcurr->next;
|
||||||
|
|
||||||
@ -1084,7 +1084,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
|
|||||||
if (patt->len >= MAXPATHLEN)
|
if (patt->len >= MAXPATHLEN)
|
||||||
if (!(buf = malloc(patt->len + 1))) return 0;
|
if (!(buf = malloc(patt->len + 1))) return 0;
|
||||||
|
|
||||||
strncpy(buf, patt->str, patt->len);
|
strlcpy(buf, patt->str, patt->len + 1);
|
||||||
buf[patt->len] = '\0';
|
buf[patt->len] = '\0';
|
||||||
for (p = buf; *p; p = CharNext(p))
|
for (p = buf; *p; p = CharNext(p))
|
||||||
if (*p == '\\')
|
if (*p == '\\')
|
||||||
@ -1373,8 +1373,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
ptr = buffer + (elements+1) * sizeof(char *);
|
ptr = buffer + (elements+1) * sizeof(char *);
|
||||||
|
|
||||||
while (curr = cmdhead) {
|
while (curr = cmdhead) {
|
||||||
strncpy(ptr, curr->str, curr->len);
|
strlcpy(ptr, curr->str, len - (elements + 1));
|
||||||
ptr[curr->len] = '\0';
|
|
||||||
*vptr++ = ptr;
|
*vptr++ = ptr;
|
||||||
ptr += curr->len + 1;
|
ptr += curr->len + 1;
|
||||||
cmdhead = curr->next;
|
cmdhead = curr->next;
|
||||||
@ -1410,6 +1409,7 @@ rb_w32_opendir(const char *filename)
|
|||||||
long len;
|
long len;
|
||||||
long idx;
|
long idx;
|
||||||
char *scanname;
|
char *scanname;
|
||||||
|
char *tmp;
|
||||||
struct stati64 sbuf;
|
struct stati64 sbuf;
|
||||||
WIN32_FIND_DATA fd;
|
WIN32_FIND_DATA fd;
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
@ -1417,7 +1417,6 @@ rb_w32_opendir(const char *filename)
|
|||||||
//
|
//
|
||||||
// check to see if we've got a directory
|
// check to see if we've got a directory
|
||||||
//
|
//
|
||||||
|
|
||||||
if (rb_w32_stati64(filename, &sbuf) < 0)
|
if (rb_w32_stati64(filename, &sbuf) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(sbuf.st_mode & S_IFDIR) &&
|
if (!(sbuf.st_mode & S_IFDIR) &&
|
||||||
@ -1430,7 +1429,6 @@ rb_w32_opendir(const char *filename)
|
|||||||
//
|
//
|
||||||
// Get us a DIR structure
|
// Get us a DIR structure
|
||||||
//
|
//
|
||||||
|
|
||||||
p = calloc(sizeof(DIR), 1);
|
p = calloc(sizeof(DIR), 1);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1438,21 +1436,21 @@ rb_w32_opendir(const char *filename)
|
|||||||
//
|
//
|
||||||
// Create the search pattern
|
// Create the search pattern
|
||||||
//
|
//
|
||||||
if (!(scanname = malloc(strlen(filename) + 2 + 1))) {
|
len = strlen(filename) + 2 + 1;
|
||||||
|
if (!(scanname = malloc(len))) {
|
||||||
free(p);
|
free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(scanname, filename);
|
strlcpy(scanname, filename, len);
|
||||||
|
|
||||||
if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL)
|
if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL)
|
||||||
strcat(scanname, "/*");
|
strlcat(scanname, "/*", len);
|
||||||
else
|
else
|
||||||
strcat(scanname, "*");
|
strlcat(scanname, "*", len);
|
||||||
|
|
||||||
//
|
//
|
||||||
// do the FindFirstFile call
|
// do the FindFirstFile call
|
||||||
//
|
//
|
||||||
|
|
||||||
fh = FindFirstFile(scanname, &fd);
|
fh = FindFirstFile(scanname, &fd);
|
||||||
free(scanname);
|
free(scanname);
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
@ -1465,7 +1463,6 @@ rb_w32_opendir(const char *filename)
|
|||||||
// now allocate the first part of the string table for the
|
// now allocate the first part of the string table for the
|
||||||
// filenames that we find.
|
// filenames that we find.
|
||||||
//
|
//
|
||||||
|
|
||||||
idx = strlen(fd.cFileName)+1;
|
idx = strlen(fd.cFileName)+1;
|
||||||
if (!(p->start = (char *)malloc(idx)) || !(p->bits = (char *)malloc(1))) {
|
if (!(p->start = (char *)malloc(idx)) || !(p->bits = (char *)malloc(1))) {
|
||||||
error:
|
error:
|
||||||
@ -1474,7 +1471,7 @@ rb_w32_opendir(const char *filename)
|
|||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(p->start, fd.cFileName);
|
strlcpy(p->start, fd.cFileName, idx);
|
||||||
p->bits[0] = 0;
|
p->bits[0] = 0;
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
SetBit(p->bits, 0);
|
SetBit(p->bits, 0);
|
||||||
@ -1489,26 +1486,23 @@ rb_w32_opendir(const char *filename)
|
|||||||
// of the previous string found.
|
// of the previous string found.
|
||||||
//
|
//
|
||||||
while (FindNextFile(fh, &fd)) {
|
while (FindNextFile(fh, &fd)) {
|
||||||
len = strlen(fd.cFileName);
|
len = strlen(fd.cFileName) + 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// bump the string table size by enough for the
|
// bump the string table size by enough for the
|
||||||
// new name and it's null terminator
|
// new name and it's null terminator
|
||||||
//
|
//
|
||||||
|
tmp = realloc(p->start, idx + len);
|
||||||
#define Renew(x, y, z) (x = (z *)xrealloc(x, y))
|
if (!tmp)
|
||||||
|
|
||||||
Renew (p->start, idx+len+1, char);
|
|
||||||
if (p->start == NULL) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
p->start = tmp;
|
||||||
strcpy(&p->start[idx], fd.cFileName);
|
strlcpy(&p->start[idx], fd.cFileName, len);
|
||||||
|
|
||||||
if (p->nfiles % 4 == 0) {
|
if (p->nfiles % 4 == 0) {
|
||||||
Renew (p->bits, p->nfiles / 4 + 1, char);
|
tmp = realloc(p->bits, p->nfiles / 4 + 1);
|
||||||
if (p->bits == NULL) {
|
if (!tmp)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
p->bits = tmp;
|
||||||
p->bits[p->nfiles / 4] = 0;
|
p->bits[p->nfiles / 4] = 0;
|
||||||
}
|
}
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
@ -1517,7 +1511,7 @@ rb_w32_opendir(const char *filename)
|
|||||||
SetBit(p->bits, p->nfiles * 2 + 1);
|
SetBit(p->bits, p->nfiles * 2 + 1);
|
||||||
|
|
||||||
p->nfiles++;
|
p->nfiles++;
|
||||||
idx += len+1;
|
idx += len;
|
||||||
}
|
}
|
||||||
FindClose(fh);
|
FindClose(fh);
|
||||||
p->size = idx;
|
p->size = idx;
|
||||||
@ -1559,7 +1553,7 @@ rb_w32_readdir(DIR *dirp)
|
|||||||
dirp->dirstr.d_namlen = strlen(dirp->curr);
|
dirp->dirstr.d_namlen = strlen(dirp->curr);
|
||||||
if (!(dirp->dirstr.d_name = malloc(dirp->dirstr.d_namlen + 1)))
|
if (!(dirp->dirstr.d_name = malloc(dirp->dirstr.d_namlen + 1)))
|
||||||
return NULL;
|
return NULL;
|
||||||
strcpy(dirp->dirstr.d_name, dirp->curr);
|
strlcpy(dirp->dirstr.d_name, dirp->curr, dirp->dirstr.d_namlen + 1);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fake inode
|
// Fake inode
|
||||||
@ -1626,11 +1620,15 @@ rb_w32_rewinddir(DIR *dirp)
|
|||||||
void
|
void
|
||||||
rb_w32_closedir(DIR *dirp)
|
rb_w32_closedir(DIR *dirp)
|
||||||
{
|
{
|
||||||
|
if (dirp) {
|
||||||
if (dirp->dirstr.d_name)
|
if (dirp->dirstr.d_name)
|
||||||
free(dirp->dirstr.d_name);
|
free(dirp->dirstr.d_name);
|
||||||
|
if (dirp->start)
|
||||||
free(dirp->start);
|
free(dirp->start);
|
||||||
|
if (dirp->bits)
|
||||||
free(dirp->bits);
|
free(dirp->bits);
|
||||||
free(dirp);
|
free(dirp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined _MT || defined __MSVCRT__) && !defined __BORLANDC__
|
#if (defined _MT || defined __MSVCRT__) && !defined __BORLANDC__
|
||||||
@ -1863,14 +1861,11 @@ rb_w32_strerror(int e)
|
|||||||
e = GetLastError();
|
e = GetLastError();
|
||||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
|
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
|
FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
|
||||||
buffer, 512, NULL) == 0) {
|
buffer, 512, NULL) == 0)
|
||||||
strcpy(buffer, "Unknown Error");
|
strlcpy(buffer, "Unknown Error", sizeof(buffer));
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strncpy(buffer, strerror(e), sizeof(buffer));
|
|
||||||
buffer[sizeof(buffer) - 1] = 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
strlcpy(buffer, strerror(e), sizeof(buffer));
|
||||||
|
|
||||||
p = buffer;
|
p = buffer;
|
||||||
while ((p = strpbrk(p, "\r\n")) != NULL) {
|
while ((p = strpbrk(p, "\r\n")) != NULL) {
|
||||||
@ -3436,14 +3431,15 @@ rb_w32_stati64(const char *path, struct stati64 *st)
|
|||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
char *buf1, *s, *end;
|
char *buf1, *s, *end;
|
||||||
int len;
|
int len, size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!path || !st) {
|
if (!path || !st) {
|
||||||
errno = EFAULT;
|
errno = EFAULT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buf1 = ALLOCA_N(char, strlen(path) + 2);
|
size = strlen(path) + 2;
|
||||||
|
buf1 = ALLOCA_N(char, size);
|
||||||
for (p = path, s = buf1; *p; p++, s++) {
|
for (p = path, s = buf1; *p; p++, s++) {
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
*s = '\\';
|
*s = '\\';
|
||||||
@ -3462,10 +3458,10 @@ rb_w32_stati64(const char *path, struct stati64 *st)
|
|||||||
if (*end == '.')
|
if (*end == '.')
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
else if (*end != '\\')
|
else if (*end != '\\')
|
||||||
strcat(buf1, "\\");
|
strlcat(buf1, "\\", size);
|
||||||
}
|
}
|
||||||
else if (*end == '\\' || (buf1 + 1 == end && *end == ':'))
|
else if (*end == '\\' || (buf1 + 1 == end && *end == ':'))
|
||||||
strcat(buf1, ".");
|
strlcat(buf1, ".", size);
|
||||||
|
|
||||||
ret = IsWinNT() ? winnt_stat(buf1, st) : stati64(buf1, st);
|
ret = IsWinNT() ? winnt_stat(buf1, st) : stati64(buf1, st);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
@ -3919,10 +3915,11 @@ rb_w32_get_environ(void)
|
|||||||
myenvtop = (char **)malloc(sizeof(char *) * (num + 1));
|
myenvtop = (char **)malloc(sizeof(char *) * (num + 1));
|
||||||
for (env = envtop, myenv = myenvtop; *env; env += strlen(env) + 1) {
|
for (env = envtop, myenv = myenvtop; *env; env += strlen(env) + 1) {
|
||||||
if (*env != '=') {
|
if (*env != '=') {
|
||||||
if (!(*myenv = (char *)malloc(strlen(env) + 1))) {
|
int len = strlen(env) + 1;
|
||||||
|
if (!(*myenv = (char *)malloc(len))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strcpy(*myenv, env);
|
strlcpy(*myenv, env, len);
|
||||||
myenv++;
|
myenv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user