Merge pull request #5646 from akallabeth/realloc_fixes

Fixed #5645: realloc return handling
This commit is contained in:
Martin Fleisz 2019-10-07 10:43:11 +02:00 committed by GitHub
commit 799685cb92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 14 deletions

View File

@ -9,6 +9,7 @@
LPSTR tr_esc_str(LPCSTR arg, bool format) LPSTR tr_esc_str(LPCSTR arg, bool format)
{ {
LPSTR tmp = NULL; LPSTR tmp = NULL;
LPSTR tmp2 = NULL;
size_t cs = 0, x, ds, len; size_t cs = 0, x, ds, len;
size_t s; size_t s;
@ -25,7 +26,12 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
ds = s + 1; ds = s + 1;
if (s) if (s)
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); {
tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
}
if (NULL == tmp) if (NULL == tmp)
{ {
@ -43,7 +49,10 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
case '<': case '<':
len = format ? 13 : 4; len = format ? 13 : 4;
ds += len - 1; ds += len - 1;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
if (NULL == tmp) if (NULL == tmp)
{ {
@ -64,7 +73,10 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
case '>': case '>':
len = format ? 14 : 4; len = format ? 14 : 4;
ds += len - 1; ds += len - 1;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
if (NULL == tmp) if (NULL == tmp)
{ {
@ -84,7 +96,10 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
case '\'': case '\'':
ds += 5; ds += 5;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
if (NULL == tmp) if (NULL == tmp)
{ {
@ -102,7 +117,10 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
case '"': case '"':
ds += 5; ds += 5;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
if (NULL == tmp) if (NULL == tmp)
{ {
@ -120,7 +138,10 @@ LPSTR tr_esc_str(LPCSTR arg, bool format)
case '&': case '&':
ds += 4; ds += 4;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR)); tmp2 = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if (!tmp2)
free(tmp);
tmp = tmp2;
if (NULL == tmp) if (NULL == tmp)
{ {

View File

@ -467,8 +467,12 @@ static BOOL region16_simplify_bands(REGION16* region)
if (finalNbRects != nbRects) if (finalNbRects != nbRects)
{ {
int allocSize = sizeof(REGION16_DATA) + (finalNbRects * sizeof(RECTANGLE_16)); REGION16_DATA* data;
region->data = realloc(region->data, allocSize); size_t allocSize = sizeof(REGION16_DATA) + (finalNbRects * sizeof(RECTANGLE_16));
data = realloc(region->data, allocSize);
if (!data)
free(region->data);
region->data = data;
if (!region->data) if (!region->data)
{ {
@ -485,10 +489,12 @@ static BOOL region16_simplify_bands(REGION16* region)
BOOL region16_union_rect(REGION16* dst, const REGION16* src, const RECTANGLE_16* rect) BOOL region16_union_rect(REGION16* dst, const REGION16* src, const RECTANGLE_16* rect)
{ {
REGION16_DATA* data;
const RECTANGLE_16* srcExtents; const RECTANGLE_16* srcExtents;
RECTANGLE_16* dstExtents; RECTANGLE_16* dstExtents;
const RECTANGLE_16* currentBand, *endSrcRect, *nextBand; const RECTANGLE_16* currentBand, *endSrcRect, *nextBand;
REGION16_DATA* newItems = NULL; REGION16_DATA* newItems = NULL;
REGION16_DATA* tmpItems = NULL;
RECTANGLE_16* dstRect = NULL; RECTANGLE_16* dstRect = NULL;
UINT32 usedRects, srcNbRects; UINT32 usedRects, srcNbRects;
UINT16 topInterBand; UINT16 topInterBand;
@ -673,7 +679,11 @@ BOOL region16_union_rect(REGION16* dst, const REGION16* src, const RECTANGLE_16*
dstExtents->bottom = MAX(rect->bottom, srcExtents->bottom); dstExtents->bottom = MAX(rect->bottom, srcExtents->bottom);
dstExtents->right = MAX(rect->right, srcExtents->right); dstExtents->right = MAX(rect->right, srcExtents->right);
newItems->size = sizeof(REGION16_DATA) + (usedRects * sizeof(RECTANGLE_16)); newItems->size = sizeof(REGION16_DATA) + (usedRects * sizeof(RECTANGLE_16));
dst->data = realloc(newItems, newItems->size); tmpItems = realloc(newItems, newItems->size);
if (!tmpItems)
free(newItems);
newItems = tmpItems;
dst->data = newItems;
if (!dst->data) if (!dst->data)
{ {
@ -717,6 +727,7 @@ BOOL region16_intersects_rect(const REGION16* src, const RECTANGLE_16* arg2)
BOOL region16_intersect_rect(REGION16* dst, const REGION16* src, const RECTANGLE_16* rect) BOOL region16_intersect_rect(REGION16* dst, const REGION16* src, const RECTANGLE_16* rect)
{ {
REGION16_DATA* data;
REGION16_DATA* newItems; REGION16_DATA* newItems;
const RECTANGLE_16* srcPtr, *endPtr, *srcExtents; const RECTANGLE_16* srcPtr, *endPtr, *srcExtents;
RECTANGLE_16* dstPtr; RECTANGLE_16* dstPtr;

View File

@ -235,7 +235,7 @@ char* crypto_cert_fingerprint(X509* xcert)
return fp_buffer; return fp_buffer;
} }
char* crypto_print_name(X509_NAME* name) static char* crypto_print_name(X509_NAME* name)
{ {
char* buffer = NULL; char* buffer = NULL;
BIO* outBIO = BIO_new(BIO_s_mem()); BIO* outBIO = BIO_new(BIO_s_mem());
@ -762,9 +762,12 @@ static int verify_cb (int ok, X509_STORE_CTX *csc)
int derr = X509_STORE_CTX_get_error_depth(csc); int derr = X509_STORE_CTX_get_error_depth(csc);
X509* where = X509_STORE_CTX_get_current_cert(csc); X509* where = X509_STORE_CTX_get_current_cert(csc);
const char* what = X509_verify_cert_error_string(err); const char* what = X509_verify_cert_error_string(err);
char* name = crypto_cert_subject(where);
WLog_WARN(TAG, "Certificate verification failure '%s (%d)' at stack position %d", what, err, derr); WLog_WARN(TAG, "Certificate verification failure '%s (%d)' at stack position %d", what, err, derr);
WLog_WARN(TAG, "%s", crypto_cert_subject(where)); WLog_WARN(TAG, "%s", name);
free(name);
} }
return ok; return ok;
} }

View File

@ -754,7 +754,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
status2 = freerdp_assistance_set_connection_string2(file, ConnectionString2, "Shadow123!"); status2 = freerdp_assistance_set_connection_string2(file, ConnectionString2, "Shadow123!");
free(ConnectionString2); free(ConnectionString2);
if ((status1 < 1) || (status < 0)) if ((status1 < 1) || (status2 < 1))
{ {
WLog_ERR(TAG, "failed to convert connection string"); WLog_ERR(TAG, "failed to convert connection string");
return -1; return -1;

View File

@ -72,7 +72,6 @@ int main(int argc, char** argv)
if ((status = shadow_server_parse_command_line(server, argc, argv)) < 0) if ((status = shadow_server_parse_command_line(server, argc, argv)) < 0)
{ {
shadow_server_command_line_status_print(server, argc, argv, status); shadow_server_command_line_status_print(server, argc, argv, status);
WLog_ERR(TAG, "Problem parsing the command line.");
goto fail_parse_command_line; goto fail_parse_command_line;
} }

View File

@ -61,6 +61,7 @@ static COMMAND_LINE_ARGUMENT_A shadow_args[] =
{ "sec-ext", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "nla extended protocol security" }, { "sec-ext", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "nla extended protocol security" },
{ "sam-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL, "NTLM SAM file for NLA authentication" }, { "sam-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL, "NTLM SAM file for NLA authentication" },
{ "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1, NULL, "Print version" }, { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1, NULL, "Print version" },
{ "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, NULL, NULL, NULL, -1, NULL, "Print the build configuration" },
{ "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?", "Print help" }, { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?", "Print help" },
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
}; };
@ -145,6 +146,11 @@ int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, c
WLog_INFO(TAG, "FreeRDP version %s (git %s)", FREERDP_VERSION_FULL, GIT_REVISION); WLog_INFO(TAG, "FreeRDP version %s (git %s)", FREERDP_VERSION_FULL, GIT_REVISION);
return COMMAND_LINE_STATUS_PRINT_VERSION; return COMMAND_LINE_STATUS_PRINT_VERSION;
} }
else if (status == COMMAND_LINE_STATUS_PRINT_BUILDCONFIG)
{
WLog_INFO(TAG, "%s", freerdp_get_build_config());
return COMMAND_LINE_STATUS_PRINT_BUILDCONFIG;
}
else if (status == COMMAND_LINE_STATUS_PRINT) else if (status == COMMAND_LINE_STATUS_PRINT)
{ {
return COMMAND_LINE_STATUS_PRINT; return COMMAND_LINE_STATUS_PRINT;

View File

@ -841,11 +841,15 @@ unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequen
static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies, static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies,
size_t mincodes, size_t numcodes, unsigned maxbitlen) size_t mincodes, size_t numcodes, unsigned maxbitlen)
{ {
unsigned* lengths;
unsigned error = 0; unsigned error = 0;
while(!frequencies[numcodes - 1] && numcodes > mincodes) numcodes--; /*trim zeroes*/ while(!frequencies[numcodes - 1] && numcodes > mincodes) numcodes--; /*trim zeroes*/
tree->maxbitlen = maxbitlen; tree->maxbitlen = maxbitlen;
tree->numcodes = (unsigned)numcodes; /*number of symbols*/ tree->numcodes = (unsigned)numcodes; /*number of symbols*/
tree->lengths = (unsigned*)realloc(tree->lengths, numcodes * sizeof(unsigned)); lengths = (unsigned*)realloc(tree->lengths, numcodes * sizeof(unsigned));
if (!lengths)
free(tree->lengths);
tree->lengths = lengths;
if(!tree->lengths) return 83; /*alloc fail*/ if(!tree->lengths) return 83; /*alloc fail*/
/*initialize all lengths to 0*/ /*initialize all lengths to 0*/
memset(tree->lengths, 0, numcodes * sizeof(unsigned)); memset(tree->lengths, 0, numcodes * sizeof(unsigned));