8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 20:43:04 +01:00

Fixed bug CORE-6253 : Crash via locked fb_lock file

This commit is contained in:
hvlad 2020-02-25 12:51:48 +02:00
parent fea20da7fa
commit 6aa0609aa7
2 changed files with 28 additions and 28 deletions

View File

@ -1627,7 +1627,7 @@ void LockManager::bug(CheckStatusWrapper* statusVector, const TEXT* string)
{ {
m_bugcheck = true; m_bugcheck = true;
const lhb* const header = m_sharedMemory->getHeader(); const lhb* const header = m_sharedMemory ? m_sharedMemory->getHeader() : NULL;
if (header) if (header)
{ {

View File

@ -356,7 +356,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (*p++ != '-') if (*p++ != '-')
{ {
FPRINTF(outfile, "%s", usage); FPRINTF(outfile, "%s", usage);
exit(FINI_OK); return FINI_OK;
} }
SCHAR c; SCHAR c;
while (c = *p++) while (c = *p++)
@ -364,7 +364,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
case '?': case '?':
FPRINTF(outfile, "%s", usage); FPRINTF(outfile, "%s", usage);
exit(FINI_OK); return FINI_OK;
break; break;
case 'o': case 'o':
@ -401,7 +401,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (sw_series <= 0) if (sw_series <= 0)
{ {
FPRINTF(outfile, "Please specify a positive value following option -s\n"); FPRINTF(outfile, "Please specify a positive value following option -s\n");
exit(FINI_OK); return FINI_OK;
} }
--argc; --argc;
break; break;
@ -428,7 +428,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
default: default:
FPRINTF(outfile, "Valid interactive switches are: a, o, t, w\n"); FPRINTF(outfile, "Valid interactive switches are: a, o, t, w\n");
exit(FINI_OK); return FINI_OK;
break; break;
} }
if (!sw_interactive) if (!sw_interactive)
@ -446,7 +446,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (sw_seconds <= 0 || sw_intervals < 0) if (sw_seconds <= 0 || sw_intervals < 0)
{ {
FPRINTF(outfile, "Please specify 2 positive values for option -i\n"); FPRINTF(outfile, "Please specify 2 positive values for option -i\n");
exit(FINI_OK); return FINI_OK;
} }
} }
--p; --p;
@ -465,7 +465,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
else else
{ {
FPRINTF(outfile, "Usage: -f <filename>\n"); FPRINTF(outfile, "Usage: -f <filename>\n");
exit(FINI_OK); return FINI_OK;
} }
break; break;
@ -478,7 +478,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
else else
{ {
FPRINTF(outfile, "Usage: -d <filename>\n"); FPRINTF(outfile, "Usage: -d <filename>\n");
exit(FINI_OK); return FINI_OK;
} }
break; break;
@ -492,7 +492,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
default: default:
FPRINTF(outfile, "%s", usage); FPRINTF(outfile, "%s", usage);
exit(FINI_OK); return FINI_OK;
break; break;
} }
} }
@ -502,7 +502,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (db_file && lock_file) if (db_file && lock_file)
{ {
FPRINTF(outfile, "Switches -d and -f cannot be specified together\n"); FPRINTF(outfile, "Switches -d and -f cannot be specified together\n");
exit(FINI_OK); return FINI_OK;
} }
else if (db_file) else if (db_file)
{ {
@ -518,7 +518,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
{ {
FPRINTF(outfile, "Unable to open the database file (%d).\n", GetLastError()); FPRINTF(outfile, "Unable to open the database file (%d).\n", GetLastError());
exit(FINI_OK); return FINI_OK;
} }
BY_HANDLE_FILE_INFORMATION file_info; BY_HANDLE_FILE_INFORMATION file_info;
GetFileInformationByHandle(h, &file_info); GetFileInformationByHandle(h, &file_info);
@ -537,7 +537,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (stat(db_name.c_str(), &statistics) == -1) if (stat(db_name.c_str(), &statistics) == -1)
{ {
FPRINTF(outfile, "Unable to open the database file.\n"); FPRINTF(outfile, "Unable to open the database file.\n");
exit(FINI_OK); return FINI_OK;
} }
const size_t len1 = sizeof(statistics.st_dev); const size_t len1 = sizeof(statistics.st_dev);
const size_t len2 = sizeof(statistics.st_ino); const size_t len2 = sizeof(statistics.st_ino);
@ -565,7 +565,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
FPRINTF(outfile, "Please specify either -d <database name> or -f <lock file name>\n\n"); FPRINTF(outfile, "Please specify either -d <database name> or -f <lock file name>\n\n");
FPRINTF(outfile, "%s", usage); FPRINTF(outfile, "%s", usage);
exit(FINI_OK); return FINI_OK;
} }
Firebird::AutoPtr<UCHAR> buffer; Firebird::AutoPtr<UCHAR> buffer;
@ -587,7 +587,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
// Mapped file is obviously too small to really be a lock file // Mapped file is obviously too small to really be a lock file
FPRINTF(outfile, "Unable to access lock table - file too small.\n"); FPRINTF(outfile, "Unable to access lock table - file too small.\n");
exit(FINI_OK); return FINI_OK;
} }
if (sw_consistency) if (sw_consistency)
@ -607,7 +607,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
catch (const Firebird::BadAlloc&) catch (const Firebird::BadAlloc&)
{ {
FPRINTF(outfile, "Insufficient memory for lock statistics.\n"); FPRINTF(outfile, "Insufficient memory for lock statistics.\n");
exit(FINI_OK); return FINI_OK;
} }
memcpy((UCHAR*) buffer, LOCK_header, extentSize); memcpy((UCHAR*) buffer, LOCK_header, extentSize);
@ -621,7 +621,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (! extData.mapFile(statusVector, extName.c_str(), 0)) if (! extData.mapFile(statusVector, extName.c_str(), 0))
{ {
FPRINTF(outfile, "Could not map extent number %d, file %s.\n", extent, extName.c_str()); FPRINTF(outfile, "Could not map extent number %d, file %s.\n", extent, extName.c_str());
exit(FINI_OK); return FINI_OK;
} }
memcpy(((UCHAR*) buffer) + extent * extentSize, extData.sh_mem_header, extentSize); memcpy(((UCHAR*) buffer) + extent * extentSize, extData.sh_mem_header, extentSize);
@ -658,7 +658,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
FPRINTF(outfile, "Insufficient memory for consistent lock statistics.\n"); FPRINTF(outfile, "Insufficient memory for consistent lock statistics.\n");
FPRINTF(outfile, "Try omitting the -c switch.\n"); FPRINTF(outfile, "Try omitting the -c switch.\n");
exit(FINI_OK); return FINI_OK;
} }
memcpy((UCHAR*) buffer, LOCK_header, LOCK_header->lhb_length); memcpy((UCHAR*) buffer, LOCK_header, LOCK_header->lhb_length);
@ -676,7 +676,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
ex.stuffException(st); ex.stuffException(st);
gds__print_status(st.begin()); gds__print_status(st.begin());
exit(FINI_OK); return FINI_OK;
} }
} }
else if (lock_file) else if (lock_file)
@ -685,7 +685,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (fd == -1) if (fd == -1)
{ {
FPRINTF(outfile, "Unable to open lock file.\n"); FPRINTF(outfile, "Unable to open lock file.\n");
exit(FINI_OK); return FINI_OK;
} }
struct stat file_stat; struct stat file_stat;
@ -693,14 +693,14 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
close(fd); close(fd);
FPRINTF(outfile, "Unable to retrieve lock file size.\n"); FPRINTF(outfile, "Unable to retrieve lock file size.\n");
exit(FINI_OK); return FINI_OK;
} }
if (!file_stat.st_size) if (!file_stat.st_size)
{ {
close(fd); close(fd);
FPRINTF(outfile, "Lock file is empty.\n"); FPRINTF(outfile, "Lock file is empty.\n");
exit(FINI_OK); return FINI_OK;
} }
try try
@ -710,7 +710,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
catch (const Firebird::BadAlloc&) catch (const Firebird::BadAlloc&)
{ {
FPRINTF(outfile, "Insufficient memory to read lock file.\n"); FPRINTF(outfile, "Insufficient memory to read lock file.\n");
exit(FINI_OK); return FINI_OK;
} }
LOCK_header = (lhb*)(UCHAR*) buffer; LOCK_header = (lhb*)(UCHAR*) buffer;
@ -720,7 +720,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (bytes_read != file_stat.st_size) if (bytes_read != file_stat.st_size)
{ {
FPRINTF(outfile, "Unable to read lock file.\n"); FPRINTF(outfile, "Unable to read lock file.\n");
exit(FINI_OK); return FINI_OK;
} }
#ifdef USE_SHMEM_EXT #ifdef USE_SHMEM_EXT
@ -736,7 +736,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
catch (const Firebird::BadAlloc&) catch (const Firebird::BadAlloc&)
{ {
FPRINTF(outfile, "Insufficient memory for lock statistics.\n"); FPRINTF(outfile, "Insufficient memory for lock statistics.\n");
exit(FINI_OK); return FINI_OK;
} }
memcpy(newBuf, LOCK_header, extentSize); memcpy(newBuf, LOCK_header, extentSize);
@ -752,14 +752,14 @@ int CLIB_ROUTINE main( int argc, char *argv[])
{ {
FPRINTF(outfile, "Unable to open lock file extent number %d, file %s.\n", FPRINTF(outfile, "Unable to open lock file extent number %d, file %s.\n",
extent, extName.c_str()); extent, extName.c_str());
exit(FINI_OK); return FINI_OK;
} }
if (read(fd, ((UCHAR*) buffer) + extent * extentSize, extentSize) != extentSize) if (read(fd, ((UCHAR*) buffer) + extent * extentSize, extentSize) != extentSize)
{ {
FPRINTF(outfile, "Could not read lock file extent number %d, file %s.\n", FPRINTF(outfile, "Could not read lock file extent number %d, file %s.\n",
extent, extName.c_str()); extent, extName.c_str());
exit(FINI_OK); return FINI_OK;
} }
close(fd); close(fd);
} }
@ -788,7 +788,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
FPRINTF(outfile, "\tUnable to read lock table version %d:%d.\n", FPRINTF(outfile, "\tUnable to read lock table version %d:%d.\n",
LOCK_header->mhb_header_version, LOCK_header->mhb_version); LOCK_header->mhb_header_version, LOCK_header->mhb_version);
} }
exit(FINI_OK); return FINI_OK;
} }
// Print lock activity report // Print lock activity report
@ -798,7 +798,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
sw_html_format = false; sw_html_format = false;
prt_lock_activity(outfile, LOCK_header, sw_interactive, prt_lock_activity(outfile, LOCK_header, sw_interactive,
(ULONG) sw_seconds, (ULONG) sw_intervals); (ULONG) sw_seconds, (ULONG) sw_intervals);
exit(FINI_OK); return FINI_OK;
} }
// Print lock header block // Print lock header block