Skip to content

Commit

Permalink
0006159: Fixed Firebird sym_hex UDF causing an access violation
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Dec 15, 2023
1 parent 0e3bdec commit 5b1e3c7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
14 changes: 8 additions & 6 deletions symmetric-server/src/databases/firebird/sym_udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ char *sym_escape(char *str)
result = (char *) ib_util_malloc(count + len + 1);
if (result == NULL)
{
return empty_str;
return NULL;
}

for (i = 0, j = 0; i < len; i++, j++)
Expand All @@ -66,15 +66,13 @@ char *sym_escape(char *str)
*/
char *sym_hex(BLOBCALLBACK blob)
{
char empty_char;
char *result, *hex_result;
long hex_result_size;
long bytes_read;
ISC_USHORT bytes_read;
long total_length;
long total_bytes_read;
long i, j;

empty_char = '\0';
bytes_read = 0;
total_bytes_read = 0;

Expand All @@ -83,7 +81,7 @@ char *sym_hex(BLOBCALLBACK blob)
result = (char *) malloc(1);
if (!result)
{
return empty_char;
return NULL;
}
}
else
Expand All @@ -92,7 +90,7 @@ char *sym_hex(BLOBCALLBACK blob)
result = (char *) malloc(total_length + 1);
if (!result)
{
return empty_char;
return NULL;
}
memset(result, 0, total_length + 1);
for (i = 0; i < blob->blob_number_segments; ++i)
Expand All @@ -106,6 +104,10 @@ char *sym_hex(BLOBCALLBACK blob)

hex_result_size = (total_bytes_read * 2) + 1;
hex_result = (char *) ib_util_malloc(hex_result_size);
if (!hex_result)
{
return NULL;
}
memset(hex_result, 0, hex_result_size);
for (i = 0, j = 0; i < total_bytes_read; i++, j += 2)
{
Expand Down
12 changes: 2 additions & 10 deletions symmetric-server/src/databases/firebird/sym_udf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@
* under the License.
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ibase.h"
#include "ib_util.h"

static char backslash_chr = '\\';
static char quote_chr = '"';
static char *empty_str = "";

typedef struct blob {
short (*blob_get_segment) ();
void *blob_handle;
long blob_number_segments;
long blob_max_segment;
long blob_total_length;
void (*blob_put_segment) ();
} *BLOBCALLBACK;

char *sym_escape(char *str);
char *sym_hex(BLOBCALLBACK blob);
Binary file modified symmetric-server/src/databases/firebird/x64/sym_udf.so
Binary file not shown.

0 comments on commit 5b1e3c7

Please sign in to comment.