From 54381b7bf946379d4dbb441adacd21a593fb4433 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 13 Oct 2015 12:03:32 -0500 Subject: [PATCH] Fix DB file parser crashes --- src/dbStatic/dbLex.l | 11 ++++++++--- src/dbStatic/dbLexRoutines.c | 1 + src/dbStatic/dbStaticLib.c | 8 ++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dbStatic/dbLex.l b/src/dbStatic/dbLex.l index c06a99242..681cb1f24 100644 --- a/src/dbStatic/dbLex.l +++ b/src/dbStatic/dbLex.l @@ -73,15 +73,20 @@ static int yyreset(void) {whitespace} ; {doublequote}({stringchar}|{escape})*{newline} { /* bad string */ - yyerror("Newline in string, closing quote missing"); + yyerrorAbort("Newline in string, closing quote missing"); } . { char message[40]; YY_BUFFER_STATE *dummy=0; - sprintf(message,"Invalid character '%c'",yytext[0]); - yyerror(message); + if (isprint((int) yytext[0])) { + sprintf(message, "Invalid character '%c'", yytext[0]); + } + else { + sprintf(message, "Invalid character 0x%2.2x", yytext[0]); + } + yyerrorAbort(message); /*The following suppresses compiler warning messages*/ if(FALSE) yyunput('c',(unsigned char *) message); if(FALSE) yy_switch_to_buffer(*dummy); diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c index efa8501df..7fde19399 100644 --- a/src/dbStatic/dbLexRoutines.c +++ b/src/dbStatic/dbLexRoutines.c @@ -12,6 +12,7 @@ /*The routines in this module are serially reusable NOT reentrant*/ +#include #include #include #include diff --git a/src/dbStatic/dbStaticLib.c b/src/dbStatic/dbStaticLib.c index 1a5d716e7..ab87911f3 100644 --- a/src/dbStatic/dbStaticLib.c +++ b/src/dbStatic/dbStaticLib.c @@ -743,8 +743,12 @@ DBENTRY * epicsShareAPI dbAllocEntry(dbBase *pdbbase) void epicsShareAPI dbFreeEntry(DBENTRY *pdbentry) { - if(pdbentry->message) free((void *)pdbentry->message); - if(pdbentry->formpvt) dbFreeForm(pdbentry); + if (!pdbentry) + return; + if (pdbentry->message) + free((void *)pdbentry->message); + if (pdbentry->formpvt) + dbFreeForm(pdbentry); dbmfFree(pdbentry); }