Skip to content

Commit ec509e4

Browse files
Merge pull request livecode#7518 from montegoulding/bugfix-16745
[[ Bug 16745 ]] Fix $_POST_RAW on Windows Server
2 parents 71babf4 + 7f49088 commit ec509e4

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

docs/notes/bugfix-16745.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# An issue causing `$_POST_RAW` on Windows to not be set for large uploads has been fixed.

engine/src/srvcgi.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,16 @@ static bool cgi_compute_post_raw_var(void *p_context, MCVariable *p_var)
993993
t_length = atoi(MCStringGetCString(*t_content_length));
994994

995995
uint32_t t_read = 0;
996+
uint32_t t_offset = 0;
996997

997998
char *t_data;
998999
t_data = new (nothrow) char[t_length];
999-
t_success = t_stdin->Read(t_data, t_length, t_read) && t_length == t_read;
1000+
while (t_stdin->Read(t_data, t_length - t_offset, t_read) && t_offset < t_length)
1001+
{
1002+
/* read until length satisfied */
1003+
t_offset += t_read;
1004+
}
1005+
t_success = t_length == t_offset;
10001006

10011007
// Store the raw POST data
10021008
if (t_success)

engine/src/srvwindows.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,28 +1241,18 @@ bool MCS_get_temporary_folder(MCStringRef &r_temp_folder)
12411241

12421242
bool MCS_create_temporary_file(MCStringRef p_path_string, MCStringRef p_prefix_string, IO_handle &r_file, MCStringRef &r_name_string)
12431243
{
1244-
const char *t_path = MCStringGetCString(p_path_string);
1245-
const char *t_prefix = MCStringGetCString(p_prefix_string);
1246-
char *t_name = (char*)MCStringGetCString(r_name_string);
1247-
12481244
bool t_success = true;
1249-
bool t_have_file = false;
12501245

1251-
char *t_temp_file = NULL;
12521246
GUID t_guid;
12531247
WCHAR *t_guid_utf16 = NULL;
12541248

1255-
HANDLE t_temp_handle = NULL;
1249+
IO_handle t_temp_handle = NULL;
12561250

1257-
while (t_success && !t_have_file)
1251+
MCAutoStringRef t_temp_file;
1252+
while (t_success && t_temp_handle == NULL)
12581253
{
12591254
CoCreateGuid(&t_guid);
12601255

1261-
if (t_temp_file != NULL)
1262-
{
1263-
MCCStringFree(t_temp_file);
1264-
t_temp_file = NULL;
1265-
}
12661256
if (t_guid_utf16 != NULL)
12671257
{
12681258
CoTaskMemFree(t_guid_utf16);
@@ -1277,28 +1267,22 @@ bool MCS_create_temporary_file(MCStringRef p_path_string, MCStringRef p_prefix_s
12771267
for (i = 0; t_guid_utf16[i] != '\0'; i++)
12781268
t_guid_string[i] = t_guid_utf16[i] & 0xFF;
12791269
t_guid_string[i] = '\0';
1280-
t_success = MCCStringFormat(t_temp_file, "%s/%s%s", t_path, t_prefix, t_guid_string);
1270+
t_success = MCStringFormat(&t_temp_file, "%@/%@%s", p_path_string, p_prefix_string, t_guid_string);
12811271
}
12821272

12831273
if (t_success)
12841274
{
1285-
t_temp_handle = CreateFileA(t_temp_file, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1286-
if (t_temp_handle != INVALID_HANDLE_VALUE)
1287-
t_have_file = true;
1288-
else
1275+
t_temp_handle = MCsystem->OpenFile(*t_temp_file, (intenum_t)kMCOpenFileModeCreate, false);
1276+
if (t_temp_handle == NULL)
12891277
t_success = GetLastError() == ERROR_FILE_EXISTS;
12901278
}
12911279
}
12921280

12931281
if (t_success)
12941282
{
1295-
r_file = MCsystem -> OpenFd(_open_osfhandle((intptr_t)t_temp_handle, _O_RDWR), kMCOpenFileModeCreate);
1296-
t_name = t_temp_file;
1297-
/* UNCHECKED */ MCStringCreateWithCString(t_name, r_name_string);
1298-
1283+
r_file = t_temp_handle;
1284+
r_name_string = t_temp_file.Take();
12991285
}
1300-
else
1301-
MCCStringFree(t_temp_file);
13021286

13031287
CoTaskMemFree(t_guid_utf16);
13041288
return t_success;

0 commit comments

Comments
 (0)