Skip to content

Commit

Permalink
Recognise bad input data
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Sep 15, 2023
1 parent a199bbc commit 93f51f4
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 24 deletions.
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

History (newest at top)
=======================

Sep 2023 (v5.4.4)
* Try to recognise some input file corruption and cleanly exit

Jun 2023 (v5.4.3)
* Update for MQ V9.3.3
* Many more QQST fields
* Many more QQST fields
* New "-f jsoncompact" option for single-line JSON records
* Add Task_Index field to channel structures, to easier tie up with MP1B output
* Correct a couple of column names in WQ structure
* Correct a couple of column names in WQ structure

Feb 2023 (v5.4.2)
* Update for MQ V9.3.2
Expand Down
5 changes: 5 additions & 0 deletions src/M
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ fi

export PLATFLAGS=$flags CC=$cc VERS=$VERS
make -e -f Makefile.unix $*
rc=$?
if [ $rc -ne 0 ]
then
exit $rc
fi

rm -f $targdir/convH $targdir/mqsmfcsv
cp convH mqsmfcsv $targdir
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CC=cc
CFLAGS= -I. -O2
PLATFLAGS=
SRC = \
mqsmf.c \
smfDDL.c \
smfPrint.c \
smfDate.c \
Expand Down Expand Up @@ -39,8 +40,7 @@ SRC = \
t123/printDataV2.c \
t123/printServerV1.c \
t123/printServerV2.c \
t180/printAMS.c \
mqsmf.c
t180/printAMS.c

HDR = mqsmfstrucU.h \
t123/smf123.h \
Expand All @@ -62,7 +62,7 @@ shipTest: mqsmfcsv
mqsmfcsv: $(SRC) $(HDR) Makefile.unix dummy
$(CC) $(PLATFLAGS) -o $@ $(SRC) $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)

mqsmfstrucU.h: convH dummy # csqdsmfc-$(VERS).h
mqsmfstrucU.h: convH dummy # csqdsmfc-$(VERS).h
(test -s csqdsmfc-$(VERS).h && convH $(VERS) < csqdsmfc-$(VERS).h > $@) || exit 0

convH: convH64.c dummy
Expand Down
62 changes: 44 additions & 18 deletions src/mqsmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static myoff_t pos;
static int offsetCorrection = 0;

static BOOL warn115_240=FALSE;
static BOOL corruptData = FALSE;

static time_t startTime = 0;
static time_t endTime = 0;
Expand Down Expand Up @@ -243,6 +244,7 @@ int main( int argc, char *argv[] )

int sectionCount;
int recordSubTypeVersion;
int triplet1Offset;

infoStream=stdout;

Expand Down Expand Up @@ -697,7 +699,18 @@ int main( int argc, char *argv[] )
/*******************************************************************/
offsetBlockStart = &pSMFMQRecord->s[0];
offsetBlockType = BT_TRIPLET;
p = &dataBuf[conv32(pSMFMQRecord->s[0].offset)];
triplet1Offset = conv32(pSMFMQRecord->s[0].offset);
p = &dataBuf[triplet1Offset];

/*
debugf(2,"Current file offset: 0x%08X\n",currentOffset);
printDEBUG("INPUT BUF",dataBuf,offset);
debugf(2,"\n p=%p bytesread=%d offset=%d\n",p,bytesRead+4,offset);
debugf(2," trip[0] tripOffset=%d [0x%08X] len=%d count=%d\n", triplet1Offset,triplet1Offset,
conv16(pSMFMQRecord->s[0].l),
conv16(pSMFMQRecord->s[0].n));
*/

if (conv16(pSMFMQRecord->s[0].l) == 4) /* There is no QWHS */
{
sectionCount = 2; /* 1 extra triplet beyond the QWHS location */
Expand All @@ -708,7 +721,24 @@ int main( int argc, char *argv[] )
else
{
char *dt[2];
int qwshlen;

pqwhs = (qwhs *)p;
qwshlen = conv16(pqwhs->qwhslen);
if (debugLevel >= 2) {
printDEBUG("QWHS",p,(qwshlen!=0)?qwshlen:0x30);
}
if (qwshlen <= 0)
{
FILE *dfp = printDEBUGStream();
fprintf(stderr,"Error: Data at file offset 0x%08X appears corrupt. Exiting the formatter.\n",currentOffset);
if (dfp) {
fprintf(dfp, "Error: Data at file offset 0x%08X appears corrupt. Exiting the formatter.\n",currentOffset);
}
corruptData = TRUE;
continue;
}

sectionCount = pqwhs->qwhsnsda[0];
convDate(pqwhs->qwhsstck,dt);
strcpy(commonF.stckFormatDate,dt[0]);
Expand Down Expand Up @@ -736,7 +766,7 @@ int main( int argc, char *argv[] )
}
break;

case SMFTYPE_ZCEE:
case SMFTYPE_ZCEE:
recordSubTypeVersion = conv32(pSMFMQRecord->Header.u.v);

switch (recordSubTypeVersion)
Expand Down Expand Up @@ -773,8 +803,9 @@ int main( int argc, char *argv[] )
}
}

if (pqwhs != NULL)
debugf(3,"Section count %d for %4.4s, qwhslen=%d\n",sectionCount,commonF.qMgr,conv16(pqwhs->qwhslen));
if (pqwhs != NULL) {
debugf(3,"Section count %d for %4.4s, qwhslen=%d\n",sectionCount,commonF.qMgr,conv16(pqwhs->qwhslen));
}

/*********************************************************************/
/* Once we know how many sections there are, copy the triplet values */
Expand All @@ -786,8 +817,9 @@ int main( int argc, char *argv[] )
/*********************************************************************/
recLength = getOffsets(sectionCount,offsetBlockStart, offsetBlockType, recordType,subTypesValid, currentOffset);
currentOffset += recLength;
if (debugLevel >= 2)
if (debugLevel >= 2) {
printDEBUG("FULL RECORD",dataBuf + offsetCorrection,recLength);
}


/*********************************************************************/
Expand Down Expand Up @@ -1185,7 +1217,7 @@ int main( int argc, char *argv[] )
exit(0);
}
}
} while (0 != bytesRead && totalRecords < maxRecords);
} while (0 != bytesRead && totalRecords < maxRecords && !corruptData);

/***********************************************************************/
/* Cleanup and exit. If we get here normally, then the checkpoint */
Expand Down Expand Up @@ -1740,26 +1772,20 @@ int getOffsets(int sectionCount,void *offsetBlockStart, int offsetBlockType, int
{
if (recordType == amsType)
{
fprintf(infoStream, "Highest doublet = %d RecLength = %d New Offset = %lld\n",
debugf(3, "Highest doublet = %d RecLength = %d New Offset = %lld\n",
h, recLength, currentOffset);
if (debugLevel >=4)
for (i=0;i<sectionCount;i++)
{
for (i=0;i<sectionCount;i++)
{
fprintf(infoStream,"Doublet %d - offset=%d len=%d \n",i,doublet[i].offset,doublet[i].l);
}
debugf(4,"Doublet %d - offset=%d len=%d \n",i,doublet[i].offset,doublet[i].l);
}
}
else
{
fprintf(infoStream, "Highest triple = %d RecLength = %d New Offset = %lld\n",
debugf(3, "Highest triple = %d RecLength = %d New Offset = %lld\n",
h, recLength, currentOffset);
if (debugLevel >=4)
for (i=0;i<sectionCount;i++)
{
for (i=0;i<sectionCount;i++)
{
fprintf(infoStream,"Triplet %d - offset=%d len=%d count=%d\n",i,triplet[i].offset,triplet[i].l,triplet[i].n);
}
debugf(4,"Triplet %d - offset=%d len=%d count=%d\n",i,triplet[i].offset,triplet[i].l,triplet[i].n);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/mqsmf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ typedef struct columnHeader_s {
/* Formatting functions - one for each element type */
/********************************************************************/
extern void printDEBUG (char *title, void *,int);
extern FILE *printDEBUGStream();
extern void printQ5ST (q5st *);
extern void printQCCT (qcct *);
extern void printQCST (qcst *);
Expand Down Expand Up @@ -260,7 +261,13 @@ extern FILE * fopenext(const char *, const char *, BOOL *);

#if !defined(debugf)
#define debugf(_level,_fmt,...) \
{if (debugLevel >= _level) fprintf(infoStream,_fmt,__VA_ARGS__);}
{if (debugLevel >= _level) { \
FILE *dfp = printDEBUGStream(); \
if (dfp) { \
fprintf(dfp,_fmt,__VA_ARGS__); \
} \
fprintf(infoStream,_fmt,__VA_ARGS__);} \
}
#endif
/*
* Convert some MQI values into the corresponding string
Expand Down
5 changes: 5 additions & 0 deletions src/printDEBUG.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ void printDEBUG(char *title, void *buf,int length)
}
return;
}

FILE *printDEBUGStream()
{
return fp;
}

0 comments on commit 93f51f4

Please sign in to comment.