Fixed bug: integer number compilation could read past end of string

This commit is contained in:
claudiol 2017-08-07 10:32:04 -04:00
parent 982088cf73
commit ee561710ba
3 changed files with 50 additions and 16 deletions

View file

@ -311,6 +311,7 @@ void MainWindow::on_actionExit_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -370,6 +371,7 @@ void MainWindow::on_actionSave_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -413,6 +415,7 @@ void MainWindow::on_actionOpen_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -506,6 +509,7 @@ void MainWindow::on_actionSaveAs_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -538,6 +542,7 @@ void MainWindow::on_actionNew_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -642,6 +647,7 @@ void MainWindow::on_actionPower_ON_triggered()
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__cpu_idle=0;
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
@ -761,7 +767,7 @@ void MainWindow::on_actionOpen_file_to_Level_1_triggered()
// NOW WORK ON THE RPL ENGINE WHILE THE THREAD IS BLOCKED
if(!LoadRPLObject(fname)) {
QMessageBox a(QMessageBox::Warning,"Error while saving","Cannot write to file "+ fname,QMessageBox::Ok,this);
QMessageBox a(QMessageBox::Warning,"Error while opening","Cannot read file. Corrupted data?\n"+ fname,QMessageBox::Ok,this);
a.exec();
return;
}

View file

@ -932,16 +932,13 @@ void LIB_HANDLER()
pos=1;
repl=(BYTEPTR)(rplPeekData(1)+1);
find=(BYTEPTR)(rplPeekData(2)+1);
str1=(BYTEPTR)(rplPeekData(3)+1);
lenstr1=rplStrLen(rplPeekData(3));
lenfind=rplStrLen(rplPeekData(2));
lenfindcp=rplStrLenCp(rplPeekData(2));
sizestr1=rplStrSize(rplPeekData(3));
sizefind=rplStrSize(rplPeekData(2));
sizerepl=rplStrSize(rplPeekData(1));
end1=str1+sizestr1;
if(lenfind>lenstr1) {
// WILL NEVER FIND A LONGER STRING INSIDE A SHORT ONE
@ -954,6 +951,11 @@ void LIB_HANDLER()
WORDPTR newstring=rplCreateStringBySize(1);
BINT newsize=0,rcount=0;
repl=(BYTEPTR)(rplPeekData(1)+1);
find=(BYTEPTR)(rplPeekData(2)+1);
str1=(BYTEPTR)(rplPeekData(3)+1);
end1=str1+sizestr1;
BYTEPTR nextchar=str1;
// DO SEARCH AND REPLACE
@ -1128,6 +1130,24 @@ void LIB_HANDLER()
rplDropData(1);
return;
case OVR_NOTEQ:
if(rplDepthData()<2) {
rplError(ERR_BADARGCOUNT);
return;
}
if( (!ISSTRING(*rplPeekData(2))) || (!ISSTRING(*rplPeekData(1)))) {
rplOverwriteData(2,(WORDPTR)one_bint);
rplDropData(1);
return;
}
if(rplStringCompare(rplPeekData(1),rplPeekData(2))) rplOverwriteData(2,(WORDPTR)zero_bint);
else rplOverwriteData(2,(WORDPTR)one_bint);
rplDropData(1);
return;
// STANDARIZED OPCODES:
// --------------------

View file

@ -1266,7 +1266,7 @@ void LIB_HANDLER()
BINT64 result;
UBINT64 uresult;
BYTEPTR strptr;
BYTEPTR strptr,strend;
int base,libbase,digit,count,neg,argnum1;
char basechr;
@ -1298,6 +1298,7 @@ void LIB_HANDLER()
// COMPILE A NUMBER TO A SINT OR A BINT, DEPENDING ON THE ACTUAL NUMERIC VALUE
result=0;
strptr=(BYTEPTR )TokenStart;
strend=(BYTEPTR)BlankStart;
base=10;
libbase=DECBINT;
neg=0;
@ -1306,28 +1307,35 @@ void LIB_HANDLER()
if(*strptr=='-') { neg=1; ++strptr; --argnum1; }
else if(*strptr=='+') { neg=0; ++strptr; --argnum1; }
if(argnum1<=0) { RetNum=ERR_NOTMINE; return; }
if(*strptr=='#') {
++strptr;
--argnum1;
// THIS IS A NUMBER WITH A BASE
basechr=strptr[argnum1-1];
if(argnum1<=0) { RetNum=ERR_NOTMINE; return; }
if( (basechr=='d') || (basechr=='D')) { --argnum1; }
if( (basechr=='h') || (basechr=='H')) { base=16; libbase=HEXBINT; --argnum1; }
if( (basechr=='o') || (basechr=='O')) { base=8; libbase=OCTBINT; --argnum1; }
if( (basechr=='b') || (basechr=='B')) { base=2; libbase=BINBINT; --argnum1; }
// THIS IS A NUMBER WITH A BASE
basechr=strend[-1];
if( (basechr=='d') || (basechr=='D')) { --argnum1; --strend; }
if( (basechr=='h') || (basechr=='H')) { base=16; libbase=HEXBINT; --argnum1; --strend; }
if( (basechr=='o') || (basechr=='O')) { base=8; libbase=OCTBINT; --argnum1; --strend; }
if( (basechr=='b') || (basechr=='B')) { base=2; libbase=BINBINT; --argnum1; --strend; }
}
if(strptr[argnum1-1]=='.') {
if(argnum1<=0) { RetNum=ERR_NOTMINE; return; }
if(strend[-1]=='.') {
// NUMBERS ENDING IN A DOT ARE APPROXIMATED
libbase|=APPROX_BIT;
--argnum1;
--strend;
}
for(count=0;count<argnum1;++count) {
digit=utf82cp((char *)strptr+count,(char *)strptr+argnum1);
if(digit<0) { ++argnum1; continue; }
digit=utf82cp((char *)strptr,(char *)strend);
strptr=(BYTEPTR)utf8skipst((char *)strptr,(char *)strend);
if(digit<0) { RetNum=ERR_NOTMINE; return; }
if((base==10) && ((WORD)digit==THOUSAND_SEP(Locale))) continue;
if((digit>='0')&&(digit<='9')) digit-=48;
else if((digit>='a')&&(digit<='f')) digit-=87;