mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-01-02 11:36:22 +01:00
modify fs_getwd so it allocates the path
This commit is contained in:
parent
95e102a90c
commit
8944ca5156
@ -58,12 +58,14 @@ DWORD request_fs_ls(Remote * remote, Packet * packet)
|
||||
DWORD request_fs_getwd(Remote * remote, Packet * packet)
|
||||
{
|
||||
Packet *response = packet_create_response(packet);
|
||||
char directory[FS_MAX_PATH];
|
||||
char *directory = NULL;
|
||||
DWORD result;
|
||||
|
||||
result = fs_getwd(directory, sizeof(directory));
|
||||
|
||||
packet_add_tlv_string(response, TLV_TYPE_DIRECTORY_PATH, directory);
|
||||
result = fs_getwd(&directory);
|
||||
if (directory != NULL) {
|
||||
packet_add_tlv_string(response, TLV_TYPE_DIRECTORY_PATH, directory);
|
||||
free(directory);
|
||||
}
|
||||
|
||||
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
|
||||
return packet_transmit(remote, response, NULL);
|
||||
@ -78,7 +80,7 @@ DWORD request_fs_getwd(Remote * remote, Packet * packet)
|
||||
DWORD request_fs_chdir(Remote * remote, Packet * packet)
|
||||
{
|
||||
Packet *response = packet_create_response(packet);
|
||||
LPCSTR directory;
|
||||
char *directory;
|
||||
DWORD result;
|
||||
directory = packet_get_tlv_value_string(packet, TLV_TYPE_DIRECTORY_PATH);
|
||||
|
||||
@ -100,7 +102,7 @@ DWORD request_fs_chdir(Remote * remote, Packet * packet)
|
||||
DWORD request_fs_mkdir(Remote * remote, Packet * packet)
|
||||
{
|
||||
Packet *response = packet_create_response(packet);
|
||||
LPCSTR directory;
|
||||
char *directory;
|
||||
DWORD result;
|
||||
directory = packet_get_tlv_value_string(packet, TLV_TYPE_DIRECTORY_PATH);
|
||||
|
||||
@ -122,7 +124,7 @@ DWORD request_fs_mkdir(Remote * remote, Packet * packet)
|
||||
DWORD request_fs_delete_dir(Remote * remote, Packet * packet)
|
||||
{
|
||||
Packet *response = packet_create_response(packet);
|
||||
LPCSTR directory;
|
||||
char *directory;
|
||||
DWORD result;
|
||||
directory = packet_get_tlv_value_string(packet, TLV_TYPE_DIRECTORY_PATH);
|
||||
|
||||
|
@ -55,7 +55,7 @@ int fs_fopen(const char *path, const char *mode, FILE **f);
|
||||
|
||||
int fs_ls(const char *directory, fs_ls_cb_t cb, void *arg);
|
||||
|
||||
int fs_getwd(char *directory, size_t len);
|
||||
int fs_getwd(char **directory);
|
||||
|
||||
int fs_mkdir(const char *directory);
|
||||
|
||||
|
@ -56,12 +56,14 @@ char * fs_expand_path(const char *regular)
|
||||
return strdup(regular);
|
||||
}
|
||||
|
||||
int fs_getwd(char *directory, size_t len)
|
||||
int fs_getwd(char **directory)
|
||||
{
|
||||
if (getcwd(directory, len) == NULL) {
|
||||
char dir[FS_MAX_PATH];
|
||||
if (getcwd(dir, sizeof(dir)) == NULL) {
|
||||
return errno;
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
*directory = strdup(dir);
|
||||
return *directory == NULL ? ERROR_NOT_ENOUGH_MEMORY : ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int fs_mkdir(const char *directory)
|
||||
|
@ -201,33 +201,22 @@ out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
int fs_getwd(char *directory, size_t len)
|
||||
int fs_getwd(char **dir)
|
||||
{
|
||||
int rc = ERROR_SUCCESS;
|
||||
wchar_t *dir_w;
|
||||
char *dir;
|
||||
wchar_t dir_w[FS_MAX_PATH];
|
||||
|
||||
dir_w = calloc(len, sizeof(wchar_t));
|
||||
if (dir_w == NULL) {
|
||||
if (GetCurrentDirectoryW(FS_MAX_PATH, dir_w) == 0) {
|
||||
rc = GetLastError();
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (GetCurrentDirectoryW(len, dir_w) == 0) {
|
||||
*dir = wchar_to_utf8(dir_w);
|
||||
if (*dir == NULL) {
|
||||
rc = GetLastError();
|
||||
goto out;
|
||||
}
|
||||
|
||||
dir = wchar_to_utf8(dir_w);
|
||||
if (dir == NULL) {
|
||||
rc = GetLastError();
|
||||
goto out;
|
||||
}
|
||||
strncpy(directory, dir, len);
|
||||
|
||||
out:
|
||||
free(dir);
|
||||
free(dir_w);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user