Skip to content

Commit 5bd9d2a

Browse files
committed
Fix crash in w32_dirent, minor spelling in scp.
1 parent 91b30b6 commit 5bd9d2a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

scp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
834834

835835
// Create a pair of pipes for communicating with ssh
836836
// which we will spawn
837-
// Do the plunmbing so that child ssh process to be spawned has its
837+
// Do the plumbing so that child ssh process to be spawned has its
838838
// standard input from the pout[0] and its standard output going to
839839
// pin[1]
840840

@@ -1006,7 +1006,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
10061006
}
10071007

10081008
/*
1009-
* This functions executes a command simlar to do_cmd(), but expects the
1009+
* This functions executes a command similar to do_cmd(), but expects the
10101010
* input and output descriptors to be setup by a previous call to do_cmd().
10111011
* This way the input and output of two commands can be connected.
10121012
*/

win32_dirent.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdio.h>
88
#include <ctype.h>
99
#include <string.h>
10+
#include <utf.h>
1011

1112
#include "win32_dirent.h"
1213

@@ -18,13 +19,16 @@ DIR * opendir(char *name)
1819
intptr_t hFile;
1920
DIR *pdir;
2021
wchar_t searchstr[MAX_PATH];
21-
wchar_t wname[MAX_PATH];
22+
wchar_t* wname = NULL;
2223
int needed;
24+
char *tmp = NULL;
2325

24-
MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, MAX_PATH);
26+
if ((wname = utf8_to_utf16(name)) == NULL)
27+
fatal("failed to covert input arguments");
2528

2629
// add *.* for Windows _findfirst() search pattern
2730
swprintf_s(searchstr, MAX_PATH, L"%s\\*.*", wname);
31+
free(wname);
2832

2933
if ((hFile = _wfindfirst(searchstr, &c_file)) == -1L) {
3034
if (1) // verbose
@@ -40,11 +44,12 @@ DIR * opendir(char *name)
4044
pdir->c_file.time_create = c_file.time_create;
4145
pdir->c_file.time_write = c_file.time_write;
4246

43-
if ((needed = WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, NULL, 0, NULL, NULL)) == 0 ||
44-
WideCharToMultiByte(CP_UTF8, 0, c_file.name, -1, pdir->c_file.name, needed, NULL, NULL) != needed)
47+
if ((tmp = utf16_to_utf8(&(c_file.name))) == NULL)
4548
fatal("failed to covert input arguments");
4649

50+
strcpy_s(pdir->c_file.name, MAX_PATH, tmp);
4751
strcpy_s(pdir->initName, sizeof(pdir->initName), pdir->c_file.name);
52+
free(tmp);
4853

4954
return pdir ;
5055
}
@@ -69,7 +74,6 @@ int closedir(DIR *dirp)
6974
by a later readdir call on the same DIR stream. */
7075
struct dirent *readdir(void *avp)
7176
{
72-
int needed;
7377
struct dirent *pdirentry;
7478
struct _wfinddata_t c_file;
7579
DIR *dirp = (DIR *)avp;
@@ -83,10 +87,9 @@ struct dirent *readdir(void *avp)
8387
}
8488
pdirentry = (struct dirent *) malloc( sizeof(struct dirent) );
8589

86-
if ((tmp = utf16_to_utf8(pdirentry->d_name)) == NULL)
90+
if ((tmp = utf16_to_utf8(&(c_file.name))) == NULL)
8791
fatal("failed to covert input arguments");
88-
strcpy(c_file.name[0], tmp);
89-
free(tmp);
92+
pdirentry->d_name= tmp;
9093
tmp = NULL;
9194

9295
pdirentry->d_ino = 1; // a fictious one like UNIX to say it is nonzero

0 commit comments

Comments
 (0)