added recoll memory allocation checks
This commit is contained in:
parent
c0aa102ac0
commit
caf54d1d7f
75
unac/unac.c
75
unac/unac.c
@ -38,6 +38,7 @@
|
|||||||
#endif /* HAVE_VSNPRINTF */
|
#endif /* HAVE_VSNPRINTF */
|
||||||
|
|
||||||
#include "unac.h"
|
#include "unac.h"
|
||||||
|
#include "unac_version.h"
|
||||||
|
|
||||||
/* Generated by builder. Do not modify. Start tables */
|
/* Generated by builder. Do not modify. Start tables */
|
||||||
/*
|
/*
|
||||||
@ -13879,7 +13880,7 @@ unac_data367
|
|||||||
* Debug level. See unac.h for a detailed discussion of the
|
* Debug level. See unac.h for a detailed discussion of the
|
||||||
* values.
|
* values.
|
||||||
*/
|
*/
|
||||||
static int debug_level = UNAC_DEBUG_NONE;
|
static int debug_level = UNAC_DEBUG_LOW;
|
||||||
|
|
||||||
#ifdef UNAC_DEBUG_AVAILABLE
|
#ifdef UNAC_DEBUG_AVAILABLE
|
||||||
|
|
||||||
@ -13947,14 +13948,14 @@ void unac_debug_callback(int level, unac_debug_print_t function, void* data)
|
|||||||
* compatibility hack introduced in some GNU/Linux distributions that
|
* compatibility hack introduced in some GNU/Linux distributions that
|
||||||
* did not know UTF-16BE.
|
* did not know UTF-16BE.
|
||||||
*/
|
*/
|
||||||
static const char* utf16be()
|
static const char* utf16be(void)
|
||||||
{
|
{
|
||||||
iconv_t cd;
|
iconv_t cd;
|
||||||
static char* name = 0;
|
static char* name = 0;
|
||||||
|
|
||||||
if(name == 0) {
|
if(name == 0) {
|
||||||
if((cd = iconv_open("UTF-16BE", "UTF-16BE")) == (iconv_t)-1) {
|
if((cd = iconv_open("UTF-16BE", "UTF-16BE")) == (iconv_t)-1) {
|
||||||
if(debug_level == UNAC_DEBUG_LOW) DEBUG("could not find UTF-16BE (see iconv -l), using UTF-16. If UTF-16 happens to be encoded in little endian, be prepared for an horrible mess.");
|
if(debug_level >= UNAC_DEBUG_LOW) DEBUG("could not find UTF-16BE (see iconv -l), using UTF-16. If UTF-16 happens to be encoded in little endian, be prepared for an horrible mess.");
|
||||||
name = "UTF-16";
|
name = "UTF-16";
|
||||||
} else {
|
} else {
|
||||||
iconv_close(cd);
|
iconv_close(cd);
|
||||||
@ -13974,14 +13975,24 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
out_size = in_length > 0 ? in_length : 1024;
|
out_size = in_length > 0 ? in_length : 1024;
|
||||||
if(*outp) {
|
if (*outp) {
|
||||||
out = *outp;
|
out = *outp;
|
||||||
/* +1 for null */
|
/* +1 for null */
|
||||||
out = realloc(out, out_size + 1);
|
out = realloc(out, out_size + 1);
|
||||||
|
if(out == 0) {
|
||||||
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
|
DEBUG("realloc %d bytes failed\n", out_size+1);
|
||||||
|
/* *outp is still valid. Let the caller free it */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* +1 for null */
|
/* +1 for null */
|
||||||
out = malloc(out_size + 1);
|
out = malloc(out_size + 1);
|
||||||
if(out == 0) return -1;
|
if (out == 0) {
|
||||||
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
|
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out_length = 0;
|
out_length = 0;
|
||||||
|
|
||||||
@ -14016,15 +14027,22 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
|||||||
DEBUG_APPEND("\n");
|
DEBUG_APPEND("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure there is enough space to hold the decomposition
|
* Make sure there is enough space to hold the decomposition
|
||||||
|
* Note: a previous realloc may have succeeded, which means that *outp
|
||||||
|
* is not valid any more. We have to do the freeing and zero out *outp
|
||||||
*/
|
*/
|
||||||
if(out_length + ((l + 1) * 2) > out_size) {
|
if(out_length + ((l + 1) * 2) > out_size) {
|
||||||
|
char *saved;
|
||||||
out_size += ((l + 1) * 2) + 1024;
|
out_size += ((l + 1) * 2) + 1024;
|
||||||
|
saved = out;
|
||||||
out = realloc(out, out_size);
|
out = realloc(out, out_size);
|
||||||
if(out == 0) {
|
if(out == 0) {
|
||||||
if(debug_level == UNAC_DEBUG_LOW)
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
DEBUG("realloc %d bytes failed\n", out_size);
|
DEBUG("realloc %d bytes failed\n", out_size);
|
||||||
|
free(saved);
|
||||||
|
*outp = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14095,10 +14113,20 @@ static int convert(const char* from, const char* to,
|
|||||||
out = *outp;
|
out = *outp;
|
||||||
/* +1 for null */
|
/* +1 for null */
|
||||||
out = realloc(out, out_size + 1);
|
out = realloc(out, out_size + 1);
|
||||||
|
if(out == 0) {
|
||||||
|
/* *outp still valid, no freeing */
|
||||||
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
|
DEBUG("realloc %d bytes failed\n", out_size+1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* +1 for null */
|
/* +1 for null */
|
||||||
out = malloc(out_size + 1);
|
out = malloc(out_size + 1);
|
||||||
if(out == 0) return -1;
|
if(out == 0) {
|
||||||
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
|
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out_remain = out_size;
|
out_remain = out_size;
|
||||||
out_base = out;
|
out_base = out;
|
||||||
@ -14150,13 +14178,24 @@ static int convert(const char* from, const char* to,
|
|||||||
case E2BIG:
|
case E2BIG:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The output does not fit in the current out buffer, enlarge it.
|
* The output does not fit in the current out buffer, enlarge it.
|
||||||
*/
|
*/
|
||||||
int length = out - out_base;
|
int length = out - out_base;
|
||||||
out_size *= 2;
|
out_size *= 2;
|
||||||
/* +1 for null */
|
{
|
||||||
out_base = realloc(out_base, out_size + 1);
|
char *saved = out_base;
|
||||||
if(out_base == 0) return -1;
|
/* +1 for null */
|
||||||
|
out_base = realloc(out_base, out_size + 1);
|
||||||
|
if (out_base == 0) {
|
||||||
|
/* *outp potentially not valid any more. Free here,
|
||||||
|
* and zero out */
|
||||||
|
if(debug_level >= UNAC_DEBUG_LOW)
|
||||||
|
DEBUG("realloc %d bytes failed\n", out_size+1);
|
||||||
|
free(saved);
|
||||||
|
*outp = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
out = out_base + length;
|
out = out_base + length;
|
||||||
out_remain = out_size - length;
|
out_remain = out_size - length;
|
||||||
}
|
}
|
||||||
@ -14184,11 +14223,13 @@ int unacmaybefold_string(const char* charset,
|
|||||||
* When converting an empty string, skip everything but alloc the
|
* When converting an empty string, skip everything but alloc the
|
||||||
* buffer if NULL pointer.
|
* buffer if NULL pointer.
|
||||||
*/
|
*/
|
||||||
if(in_length <= 0) {
|
if (in_length <= 0) {
|
||||||
if(!*outp)
|
if(!*outp) {
|
||||||
*outp = malloc(32);
|
if ((*outp = malloc(32)) == 0)
|
||||||
(*outp)[0] = '\0';
|
return -1;
|
||||||
*out_lengthp = 0;
|
}
|
||||||
|
(*outp)[0] = '\0';
|
||||||
|
*out_lengthp = 0;
|
||||||
} else {
|
} else {
|
||||||
char* utf16 = 0;
|
char* utf16 = 0;
|
||||||
size_t utf16_length = 0;
|
size_t utf16_length = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user