From 3ba471176ef6735d4d220bdf0d700cfd040f7111 Mon Sep 17 00:00:00 2001 From: James Lee Date: Tue, 13 Mar 2012 01:10:22 -0600 Subject: [PATCH] Return an appropriate error when stat() fails Tested on Linux and Windows [Fixes #6517] --- .../source/extensions/stdapi/server/fs/file.c | 9 +++------ .../source/extensions/stdapi/server/fs/fs_util.c | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/external/source/meterpreter/source/extensions/stdapi/server/fs/file.c b/external/source/meterpreter/source/extensions/stdapi/server/fs/file.c index 121bc06345..461368208b 100644 --- a/external/source/meterpreter/source/extensions/stdapi/server/fs/file.c +++ b/external/source/meterpreter/source/extensions/stdapi/server/fs/file.c @@ -271,11 +271,8 @@ DWORD request_fs_stat(Remote *remote, Packet *packet) result = ERROR_NOT_ENOUGH_MEMORY; else { - // Stat the file using the Microsoft stat wrapper so that we don't have to - // do translations - if (fs_stat(expanded, &buf) < 0) - result = GetLastError(); - else + result = fs_stat(expanded, &buf); + if (0 == result) packet_add_tlv_raw(response, TLV_TYPE_STAT_BUF, &buf, sizeof(buf)); } @@ -288,7 +285,7 @@ DWORD request_fs_stat(Remote *remote, Packet *packet) if (expanded) free(expanded); - return ERROR_SUCCESS; + return result; } /* diff --git a/external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c b/external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c index af5b3af8a1..ce89dc6302 100644 --- a/external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c +++ b/external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c @@ -64,6 +64,10 @@ int fs_stat(LPCSTR filename, struct meterp_stat *buf) { buf->st_ctime = (unsigned long long)sbuf.st_ctime; return 0; } else { - return ret; +#ifdef _WIN32 + return GetLastError(); +#else + return errno; +#endif } }