Browse Source

Improve token buffer size checks.

  * For settings comparison: call CompareByte only on copy_size.
  * For mesgnb: verify that there is enough memory space
    in rest of tokenbuf to hold the number of messages.
  + Add a check that tbi is not greater than tokenbufsize.
Pierre Muller 1 year ago
parent
commit
98ef2773e0
1 changed files with 11 additions and 2 deletions
  1. 11 2
      compiler/utils/ppuutils/ppudump.pp

+ 11 - 2
compiler/utils/ppuutils/ppudump.pp

@@ -2709,7 +2709,7 @@ begin
                     stbi:=tbi;
                     tokenreadsettings(new_settings, copy_size);
                     tbi:=stbi+copy_size;
-                    if CompareByte(new_settings,prev_settings,sizeof(new_settings))<>0 then
+                    if CompareByte(new_settings,prev_settings,copy_size)<>0 then
                       begin
                         dump_new_settings;
                         writeln;
@@ -2725,6 +2725,10 @@ begin
                     inc(tbi);
                     mesgnb:=gettokenbufsizeint;;
                     writeln([space,mesgnb,' messages: ']);
+                    if (tbi+2*sizeof(longint)*mesgnb>tokenbufsize) then
+                      begin
+                        WriteError('!! Error: number of messages incompatible with token buffer size');
+                      end;
                     for nb:=1 to mesgnb do
                       begin
                         msgvalue:=gettokenbuflongint;
@@ -2774,7 +2778,12 @@ begin
       if tbi<tokenbufsize then
         write(',');
     end;
-  writeln;
+  if (tbi>tokenbufsize) then
+    begin
+      WriteError('!! Error: read past of token buffer size');
+    end
+  else
+    writeln;
   StrAppend(genstr,linestr);
   writeln(['##',genstr,'##']);
 end;