Skip to content

Commit

Permalink
Merge pull request liexusong#57 from imaben/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
liexusong authored Mar 25, 2017
2 parents db18293 + 38c609c commit 5aaaf0c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
126 changes: 63 additions & 63 deletions beast.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@
#include <signal.h>
#include <time.h>

#ifdef PHP_WIN32
#include <WinSock2.h>
#include <Iphlpapi.h>
#if ZEND_MODULE_API_NO >= 20151012
#pragma comment(lib, "php7.lib")
#else
#pragma comment(lib, "php5.lib")
#endif
#pragma comment(lib, "Iphlpapi.lib")
#else
#include <pwd.h>
#include <unistd.h>
#endif

typedef struct yy_buffer_state *YY_BUFFER_STATE;

#include "zend.h"
Expand All @@ -67,6 +53,20 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
#include "beast_module.h"
#include "file_handler.h"

#ifdef PHP_WIN32
#include <WinSock2.h>
#include <Iphlpapi.h>
#if ZEND_MODULE_API_NO >= 20151012
#pragma comment(lib, "php7.lib")
#else
#pragma comment(lib, "php5.lib")
#endif
#pragma comment(lib, "Iphlpapi.lib")
#else
#include <pwd.h>
#include <unistd.h>
#endif

#if ZEND_MODULE_API_NO >= 20151012
# define BEAST_RETURN_STRING(str, dup) RETURN_STRING(str)
#else
Expand Down Expand Up @@ -531,12 +531,12 @@ cgi_compile_file(zend_file_handle *h, int type TSRMLS_DC)
int destroy_file_handler = 0;


filep = zend_fopen(h->filename, &opened_path TSRMLS_CC);
if (filep != NULL) {
fd = fileno(filep);
} else {
filep = zend_fopen(h->filename, &opened_path TSRMLS_CC);
if (filep != NULL) {
fd = fileno(filep);
} else {
goto final;
}
}

retval = decrypt_file(h->filename, fd, &buf, &size,
&free_buffer, &ops TSRMLS_CC);
Expand Down Expand Up @@ -922,49 +922,49 @@ static char *get_mac_address(char *networkcard)
{
#ifdef PHP_WIN32

// For windows
ULONG size = sizeof(IP_ADAPTER_INFO);
int ret, i;
char *address = NULL;
char buf[128] = { 0 }, *pos;

PIP_ADAPTER_INFO pCurrentAdapter = NULL;
PIP_ADAPTER_INFO pIpAdapterInfo = (PIP_ADAPTER_INFO)malloc(sizeof(*pIpAdapterInfo));
if (!pIpAdapterInfo) {
beast_write_log(beast_log_error, "Failed to allocate memory for IP_ADAPTER_INFO");
return NULL;
}

ret = GetAdaptersInfo(pIpAdapterInfo, &size);
if (ERROR_BUFFER_OVERFLOW == ret) {
// see ERROR_BUFFER_OVERFLOW https://msdn.microsoft.com/en-us/library/aa365917(VS.85).aspx
free(pIpAdapterInfo);
pIpAdapterInfo = (PIP_ADAPTER_INFO)malloc(size);

ret = GetAdaptersInfo(pIpAdapterInfo, &size);
}

if (ERROR_SUCCESS != ret) {
beast_write_log(beast_log_error, "Failed to get network adapter information");
free(pIpAdapterInfo);
return NULL;
}

pCurrentAdapter = pIpAdapterInfo;
do {
if (strcmp(pCurrentAdapter->AdapterName, networkcard) == 0) {
for (i = 0, pos = buf; i < pCurrentAdapter->AddressLength; i++, pos += 3) {
sprintf(pos, "%.2X-", (int)pCurrentAdapter->Address[i]);
}
*(--pos) = '\0'; // remove last -
address = strdup(buf);
break;
}
pCurrentAdapter = pCurrentAdapter->Next;
} while (pCurrentAdapter);

free(pIpAdapterInfo);
return address;
// For windows
ULONG size = sizeof(IP_ADAPTER_INFO);
int ret, i;
char *address = NULL;
char buf[128] = { 0 }, *pos;

PIP_ADAPTER_INFO pCurrentAdapter = NULL;
PIP_ADAPTER_INFO pIpAdapterInfo = (PIP_ADAPTER_INFO)malloc(sizeof(*pIpAdapterInfo));
if (!pIpAdapterInfo) {
beast_write_log(beast_log_error, "Failed to allocate memory for IP_ADAPTER_INFO");
return NULL;
}

ret = GetAdaptersInfo(pIpAdapterInfo, &size);
if (ERROR_BUFFER_OVERFLOW == ret) {
// see ERROR_BUFFER_OVERFLOW https://msdn.microsoft.com/en-us/library/aa365917(VS.85).aspx
free(pIpAdapterInfo);
pIpAdapterInfo = (PIP_ADAPTER_INFO)malloc(size);

ret = GetAdaptersInfo(pIpAdapterInfo, &size);
}

if (ERROR_SUCCESS != ret) {
beast_write_log(beast_log_error, "Failed to get network adapter information");
free(pIpAdapterInfo);
return NULL;
}

pCurrentAdapter = pIpAdapterInfo;
do {
if (strcmp(pCurrentAdapter->AdapterName, networkcard) == 0) {
for (i = 0, pos = buf; i < pCurrentAdapter->AddressLength; i++, pos += 3) {
sprintf(pos, "%.2X-", (int)pCurrentAdapter->Address[i]);
}
*(--pos) = '\0'; // remove last -
address = strdup(buf);
break;
}
pCurrentAdapter = pCurrentAdapter->Next;
} while (pCurrentAdapter);

free(pIpAdapterInfo);
return address;

#else

Expand Down Expand Up @@ -1361,6 +1361,6 @@ PHP_FUNCTION(beast_support_filesize)
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim600: noet sw=4 ts=4 fdm=marker expandtab
* vim<600: noet sw=4 ts=4
*/
2 changes: 1 addition & 1 deletion php_beast.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ ZEND_END_MODULE_GLOBALS(beast)
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim600: noet sw=4 ts=4 fdm=marker expandtab
* vim<600: noet sw=4 ts=4
*/

0 comments on commit 5aaaf0c

Please sign in to comment.