mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-10-31 01:11:29 +01:00 
			
		
		
		
	* fixed potential buffer overflow in FPC_WRITE_TEXT_PCHAR_AS_ARRAY (merged)
This commit is contained in:
		
							parent
							
								
									547bc5f275
								
							
						
					
					
						commit
						faad9460c8
					
				| @ -439,6 +439,19 @@ end; | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Procedure Writeln_End(var f:TextRec);[Public,Alias:'FPC_WRITELN_END']; | Procedure Writeln_End(var f:TextRec);[Public,Alias:'FPC_WRITELN_END']; | ||||||
|  | const | ||||||
|  | {$IFDEF SHORT_LINEBREAK} | ||||||
|  |   eollen=1; | ||||||
|  |   eol : array[0..0] of char=(#10);
 | ||||||
|  | {$ELSE SHORT_LINEBREAK} | ||||||
|  | {$ifdef MAC_LINEBREAK} | ||||||
|  |   eollen=1; | ||||||
|  |   eol : array[0..0] of char=(#13);
 | ||||||
|  | {$else MAC_LINEBREAK} | ||||||
|  |   eollen=2; | ||||||
|  |   eol : array[0..1] of char=(#13,#10);
 | ||||||
|  | {$endif MAC_LINEBREAK} | ||||||
|  | {$ENDIF SHORT_LINEBREAK} | ||||||
| begin | begin | ||||||
|   If InOutRes <> 0 then exit; |   If InOutRes <> 0 then exit; | ||||||
|   case f.mode of |   case f.mode of | ||||||
| @ -484,9 +497,12 @@ Begin | |||||||
|     fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }: |     fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }: | ||||||
|       begin |       begin | ||||||
|         p:=pchar(@s); |         p:=pchar(@s); | ||||||
|         ArrayLen:=StrLen(p); |         { can't use StrLen, since that one could try to read past the end } | ||||||
|         if ArrayLen>sizeof(s) then |         { of the heap (JM)                                                } | ||||||
|           ArrayLen:=sizeof(s); |         ArrayLen:=IndexByte(p,sizeof(s),0); | ||||||
|  |         { IndexByte returns -1 if not found (JM) } | ||||||
|  |         if ArrayLen = -1 then | ||||||
|  |           ArrayLen := sizeof(s); | ||||||
|         If Len>ArrayLen Then |         If Len>ArrayLen Then | ||||||
|           WriteBlanks(f,Len-ArrayLen); |           WriteBlanks(f,Len-ArrayLen); | ||||||
|         WriteBuffer(f,p^,ArrayLen); |         WriteBuffer(f,p^,ArrayLen); | ||||||
| @ -1031,7 +1047,10 @@ end; | |||||||
| 
 | 
 | ||||||
| { | { | ||||||
|   $Log$ |   $Log$ | ||||||
|   Revision 1.5  2001-03-21 23:29:40  florian |   Revision 1.6  2001-04-08 13:21:30  jonas | ||||||
|  |     * fixed potential buffer overflow in FPC_WRITE_TEXT_PCHAR_AS_ARRAY (merged) | ||||||
|  | 
 | ||||||
|  |   Revision 1.5  2001/03/21 23:29:40  florian | ||||||
|     + sLineBreak and misc. stuff for Kylix compatiblity |     + sLineBreak and misc. stuff for Kylix compatiblity | ||||||
| 
 | 
 | ||||||
|   Revision 1.4  2000/11/23 13:14:02  jonas |   Revision 1.4  2000/11/23 13:14:02  jonas | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Jonas Maebe
						Jonas Maebe