Checks for NULL pointers and result of read() for Squish and Jam
This commit is contained in:
parent
7ccca29f1d
commit
11d0b8bb0a
@ -152,7 +152,7 @@ void GUser::seekwrite()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int GUser::find(const char* __name, char* __result, int __wildcards) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <gmemdbg.h>
|
||||
#include <gdbgtrk.h>
|
||||
#include <gstrall.h>
|
||||
@ -39,12 +39,23 @@
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int JamArea::load_message(int __mode, gmsg* __msg, JamHdr& __hdr) {
|
||||
ssize_t rwresult=0;
|
||||
|
||||
// Read index record for msg
|
||||
JamIndex _idx;
|
||||
memset(&_idx, 0, sizeof(JamIndex));
|
||||
lseekset(data->fhjdx, __msg->msgno-data->hdrinfo.basemsgnum, sizeof(JamIndex));
|
||||
read(data->fhjdx, &_idx, sizeof(JamIndex));
|
||||
rwresult = read(data->fhjdx, &_idx, sizeof(JamIndex));
|
||||
if( rwresult!=sizeof(JamIndex) ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! JamArea::load_message: index file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! JamArea::load_message: can't read index data");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(_idx.hdroffset == 0xFFFFFFFFL) {
|
||||
GFTRK(0);
|
||||
@ -54,7 +65,17 @@ int JamArea::load_message(int __mode, gmsg* __msg, JamHdr& __hdr) {
|
||||
// Read message header
|
||||
memset(&__hdr, 0, sizeof(JamHdr));
|
||||
lseekset(data->fhjhr, _idx.hdroffset);
|
||||
read(data->fhjhr, &__hdr, sizeof(JamHdr));
|
||||
rwresult = read(data->fhjhr, &__hdr, sizeof(JamHdr));
|
||||
if( rwresult!=sizeof(JamHdr) ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! JamArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! JamArea::load_message: can't read header");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strncmp(__hdr.signature, "JAM", 4) != 0) {
|
||||
WideLog->printf("! Invalid signature found in %s (msgno %d).", path(), __msg->msgno);
|
||||
@ -113,13 +134,26 @@ int JamArea::load_message(int __mode, gmsg* __msg, JamHdr& __hdr) {
|
||||
// Allocate space for kludge versions of the subfields
|
||||
char* _kludges = (char*)throw_malloc((uint)(__hdr.subfieldlen*2)+1);
|
||||
*_kludges = NUL;
|
||||
|
||||
|
||||
// Allocate space for seenby/paths
|
||||
char* _kludges2 = (char*)throw_malloc((uint)(__hdr.subfieldlen*2)+1);
|
||||
*_kludges2 = NUL;
|
||||
|
||||
// Read the subfields
|
||||
read(data->fhjhr, _subfield, (uint)__hdr.subfieldlen);
|
||||
rwresult = read(data->fhjhr, _subfield, (uint)__hdr.subfieldlen);
|
||||
if( rwresult!=(ssize_t)__hdr.subfieldlen ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! JamArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! JamArea::load_message: can't read Jam subfield");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
throw_free(_subfield);
|
||||
throw_free(_kludges);
|
||||
throw_free(_kludges2);
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pointer to the subfields
|
||||
JamSubField* _subfieldptr = (JamSubField*)_subfield;
|
||||
@ -344,7 +378,20 @@ int JamArea::load_message(int __mode, gmsg* __msg, JamHdr& __hdr) {
|
||||
|
||||
// Read the message text
|
||||
lseekset(data->fhjdt, __hdr.offset);
|
||||
read(data->fhjdt, __msg->txt+_kludgelen1, (uint)_msgsize);
|
||||
rwresult = read(data->fhjdt, __msg->txt+_kludgelen1, (uint)_msgsize);
|
||||
if( rwresult!=(ssize_t)_msgsize ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! JamArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! JamArea::load_message: can't read Jam msgtext");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
throw_free(_subfield);
|
||||
throw_free(_kludges);
|
||||
throw_free(_kludges2);
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is there a CR at the end?
|
||||
{
|
||||
@ -379,6 +426,11 @@ int JamArea::load_message(int __mode, gmsg* __msg, JamHdr& __hdr) {
|
||||
|
||||
int JamArea::load_hdr(gmsg* __msg) {
|
||||
|
||||
if( __msg == NULL )
|
||||
{
|
||||
WideLog->printf("! JamArea::load_hdr() is called with NULL pointer." );
|
||||
return false;
|
||||
}
|
||||
GFTRK("JamArea::load_hdr");
|
||||
|
||||
JamHdr _hdr;
|
||||
@ -390,6 +442,11 @@ int JamArea::load_hdr(gmsg* __msg) {
|
||||
|
||||
int JamArea::load_msg(gmsg* __msg) {
|
||||
|
||||
if( __msg == NULL )
|
||||
{
|
||||
WideLog->printf("! JamArea::load_msg() is called with NULL pointer." );
|
||||
return false;
|
||||
}
|
||||
GFTRK("JamArea::load_msg");
|
||||
|
||||
JamHdr _hdr;
|
||||
@ -398,4 +455,3 @@ int JamArea::load_msg(gmsg* __msg) {
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) {
|
||||
ssize_t rwresult=0;
|
||||
|
||||
// Setup some local variables for speed
|
||||
int _fhsqd = data->fhsqd;
|
||||
@ -53,11 +54,31 @@ int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) {
|
||||
SqshFrm _frm;
|
||||
memset(&_frm, 0, sizeof(SqshFrm));
|
||||
lseekset(_fhsqd, _idx[_reln-1].offset);
|
||||
read(_fhsqd, &_frm, sizeof(SqshFrm));
|
||||
rwresult = read(_fhsqd, &_frm, sizeof(SqshFrm));
|
||||
if( rwresult!=sizeof(SqshFrm) ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! SquishArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! SquishArea::load_message: can't read Squish frame");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the message header
|
||||
memset(&__hdr, 0, sizeof(SqshHdr));
|
||||
read(_fhsqd, &__hdr, sizeof(SqshHdr));
|
||||
rwresult = read(_fhsqd, &__hdr, sizeof(SqshHdr));
|
||||
if( rwresult!=sizeof(SqshHdr) ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! SquishArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! SquishArea::load_message: can't read Squish message header");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read control info and message text
|
||||
if(__mode & GMSG_TXT) {
|
||||
@ -68,7 +89,18 @@ int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) {
|
||||
char* _dest = __msg->txt = (char*)throw_calloc(1, (uint)(1+_frm.ctlsize+_frm.totsize-sizeof(SqshHdr)));
|
||||
char* _src = _dest + (uint)_frm.ctlsize;
|
||||
*_src = NUL;
|
||||
read(_fhsqd, _src, (uint)_frm.ctlsize);
|
||||
rwresult = read(_fhsqd, _src, (uint)_frm.ctlsize);
|
||||
if( rwresult!=_frm.ctlsize ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! SquishArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! SquishArea::load_message: can't read Squish message kludges");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
throw_free(__msg->txt);
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert Squish control info to true kludges
|
||||
while(*_src and (*_src == CTRL_A) and _src[1]) {
|
||||
@ -89,7 +121,18 @@ int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) {
|
||||
|
||||
// Read the message text right after the kludges
|
||||
uint _txtlen = (uint)(_frm.totsize - _frm.ctlsize - sizeof(SqshHdr));
|
||||
read(_fhsqd, _dest, _txtlen);
|
||||
rwresult = read(_fhsqd, _dest, _txtlen);
|
||||
if( rwresult!=_txtlen ) {
|
||||
if( rwresult<0 )
|
||||
WideLog->printf("! SquishArea::load_message: data file read error \"%s\"", strerror(errno));
|
||||
if( rwresult>=0 )
|
||||
WideLog->printf("! SquishArea::load_message: can't read Squish message text");
|
||||
WideLog->printf(": Info: Your msgbase is corrupted.");
|
||||
WideLog->printf("+ Advice: Run a msgbase index rebuild/recover utility.");
|
||||
throw_free(__msg->txt);
|
||||
GFTRK(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the text is NUL terminated
|
||||
_dest[_txtlen] = NUL;
|
||||
@ -180,6 +223,11 @@ int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) {
|
||||
|
||||
int SquishArea::load_hdr(gmsg* __msg) {
|
||||
|
||||
if( __msg == NULL )
|
||||
{
|
||||
WideLog->printf("! SquishArea::load_hdr() is called with NULL pointer." );
|
||||
return false;
|
||||
}
|
||||
GFTRK("SquishLoadHdr");
|
||||
|
||||
SqshHdr _hdr;
|
||||
@ -191,6 +239,11 @@ int SquishArea::load_hdr(gmsg* __msg) {
|
||||
|
||||
int SquishArea::load_msg(gmsg* __msg) {
|
||||
|
||||
if( __msg == NULL )
|
||||
{
|
||||
WideLog->printf("! SquishArea::load_msg() is called with NULL pointer." );
|
||||
return false;
|
||||
}
|
||||
GFTRK("SquishLoadMsg");
|
||||
|
||||
SqshHdr _hdr;
|
||||
|
Reference in New Issue
Block a user