8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 06:03:02 +01:00

Fix some issues: wrong pathname used for localized msgs, possibly trash stored in msg file, some obvious checks, etc.

This commit is contained in:
robocop 2008-03-16 13:38:58 +00:00
parent 52bf2414e6
commit 4d4b18c115

View File

@ -47,6 +47,7 @@ typedef msgnod* msgnod_ptr_array[max_levels];
DATABASE DB = "msg.fdb";
static void ascii_str_to_upper(TEXT*);
static char* copy_terminate(char* dest, const char* src, size_t bufsize);
static USHORT do_msgs(const TEXT*, const TEXT*, bool);
static void propagate(msgnod**, msgnod**, ULONG, ULONG);
static SLONG write_bucket(const msgnod*, USHORT);
@ -115,23 +116,34 @@ int CLIB_ROUTINE main( int argc, char** argv)
{
switch (UPPER(p[1])) {
case 'D':
strncpy(db_file, *argv++, MAXPATHLEN);
db_file[MAXPATHLEN - 1] = 0;
if (argv >= end_args)
sw_bad = true;
else
copy_terminate(db_file, *argv++, MAXPATHLEN);
break;
case 'F':
strncpy(filename, *argv++, MAXPATHLEN);
filename[MAXPATHLEN - 1] = 0;
if (argv >= end_args)
sw_bad = true;
else
copy_terminate(filename, *argv++, MAXPATHLEN);
break;
case 'P':
strncpy(pathbuffer, *argv++, MAXPATHLEN);
pathbuffer[MAXPATHLEN - 1] = 0;
pathname = pathbuffer;
if (argv >= end_args)
sw_bad = true;
else
{
copy_terminate(pathbuffer, *argv++, MAXPATHLEN);
pathname = pathbuffer;
}
break;
case 'L':
locale = *argv++;
if (argv >= end_args)
sw_bad = true;
else
locale = *argv++;
break;
case 'W':
@ -168,7 +180,9 @@ int CLIB_ROUTINE main( int argc, char** argv)
pathname[len + 1] = 0;
}
}
const size_t separator_pos = pathname ? strlen(pathname) : 0;
/* check for the locale option */
if (!locale) { // no locale given: do the regular US msgs
@ -211,12 +225,12 @@ int CLIB_ROUTINE main( int argc, char** argv)
strcat(pathname, filename);
printf(" to file %s\n", pathname);
do_msgs(pathname, this_locale, sw_warning);
pathname[separator_pos] = 0; // for the next iteration.
}
else {
printf(" to file %s\n", filename);
do_msgs(filename, this_locale, sw_warning);
}
pathname = NULL;
END_FOR;
}
else {
@ -261,6 +275,29 @@ static void ascii_str_to_upper( TEXT* s)
}
static char* copy_terminate(char* dest, const char* src, size_t bufsize)
{
/**************************************
*
* c o p y _ t e r m i n a t e
*
**************************************
*
* Functional description
* Do the same as strncpy but ensure the null terminator is written.
* To avoid putting here #include "../common/utils_proto.h"
*
**************************************/
if (!bufsize) // Was it a joke?
return dest;
--bufsize;
strncpy(dest, src, bufsize);
dest[bufsize] = 0;
return dest;
}
static USHORT do_msgs( const TEXT* filename, const TEXT* locale, bool sw_warning)
{
/**************************************
@ -347,7 +384,8 @@ static USHORT do_msgs( const TEXT* filename, const TEXT* locale, bool sw_warning
leaf_node->msgrec_code = prior_code = MSG_NUMBER(X.FAC_CODE, X.NUMBER);
leaf_node->msgrec_length = len;
leaf_node->msgrec_flags = X.FLAGS;
// Let's not store trash in flags.
leaf_node->msgrec_flags = X.FLAGS.NULL ? 0 : X.FLAGS;
//n = OFFSETA(MSGREC, msgrec_text) + len; // useless? See assignment below.
TEXT* p = leaf_node->msgrec_text;
memcpy(p, msg_text, len);
@ -462,7 +500,7 @@ static SLONG write_bucket( const msgnod* bucket, USHORT length)
exit(FINI_ERROR);
}
SLONG zero_bytes = 0;
const SLONG zero_bytes = 0;
n = write(global_file, &zero_bytes, padded_length - length);
if (n == -1) {
fprintf(stderr, "IO error on write()\n");
@ -484,14 +522,12 @@ static void sanitize( TEXT* locale)
*
* Functional description
* Clean up a locale to make it acceptable for use in file names
* for Windows NT, PC and mpexl: remove any '.' or '_' for mpexl,
* replace any period with '_' for NT or PC.
* for Windows NT: replace any period with '_'
* Keep this in sync with gds.cpp
*
**************************************/
while (*locale) {
const SSHORT ch = *locale;
if (ch == '.')
if (*locale == '.')
*locale = '_';
locale++;
}