Merge pull request #201 from wiidev/master

Use MEM2 and improve formatting
This commit is contained in:
Fledge68 2020-09-14 15:21:40 -05:00 committed by GitHub
commit 2405ad2aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 125 deletions

View File

@ -31,8 +31,7 @@
#ifndef BASE64_H
#define BASE64_H
#include <stdio.h>
#include <stdlib.h>
#include "memory/mem2.hpp"
static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@ -81,7 +80,7 @@ char* base64( const void* binaryData, int len, int *flen )
int pad = ((modulusLen & 1) << 1) + ((modulusLen & 2) >> 1); // 2 gives 1 and 1 gives 2, but 0 gives 0.
*flen = 4 * (len + pad) / 3;
res = (char*) malloc( *flen + 1 ); // and one for the null
res = (char *)MEM2_alloc(*flen + 1); // and one for the null
if (!res)
return 0;
@ -123,16 +122,19 @@ unsigned char* unbase64( const char* ascii, int len, int *flen )
int charNo;
int pad = 0;
if ((len <= 0) || (len % 4 != 0)) { // 2 accesses below would be OOB.
if ((len <= 0) || (len % 4 != 0))
{ // 2 accesses below would be OOB.
// catch empty string or incorrect padding size, return NULL as result.
*flen = 0;
return 0;
}
if( safeAsciiPtr[ len-1 ]=='=' ) ++pad;
if( safeAsciiPtr[ len-2 ]=='=' ) ++pad;
if (safeAsciiPtr[len - 1] == '=')
++pad;
if (safeAsciiPtr[len - 2] == '=')
++pad;
*flen = 3 * len / 4 - pad;
bin = (unsigned char*)malloc( *flen );
bin = (unsigned char *)MEM2_alloc(*flen);
if (!bin)
return 0;

View File

@ -268,7 +268,7 @@ bool connect_proxy(HTTP_INFO *httpinfo, char *host, char *username, char *passwo
if (!(auth = base64(credentials, strlen(credentials), &len)))
return false;
len = snprintf(request, sizeof(request), "CONNECT %s:%i HTTP/1.1\r\nProxy-Authorization: Basic %s\r\nUser-Agent: curl/7.55.1\r\n\r\n", host, httpinfo->use_https ? 443 : 80, auth);
free(auth);
MEM2_free(auth);
}
else
len = snprintf(request, sizeof(request), "CONNECT %s:%i HTTP/1.1\r\nUser-Agent: curl/7.55.1\r\n\r\n", host, httpinfo->use_https ? 443 : 80);

View File

@ -20,7 +20,7 @@ void getProxyInfo()
int fd = ISFS_Open("/shared2/sys/net/02/config.dat", ISFS_OPEN_READ);
if (fd >= 0)
{
fstats stats ATTRIBUTE_ALIGN(32) = {};
fstats stats ATTRIBUTE_ALIGN(32);
if(ISFS_GetFileStats(fd, &stats) >= 0)
{
if (stats.file_length > 0)