* fixed reading past end-of-heap again (correctly this time I hope)

This commit is contained in:
Jonas Maebe 2000-07-01 10:52:12 +00:00
parent f806e08f22
commit 964dd80cda

View File

@ -18,75 +18,90 @@
function strpas(p : pchar) : string; function strpas(p : pchar) : string;
begin begin
asm asm
movl __RESULT,%edi
movb $1,%cl
movl p,%esi movl p,%esi
// skip length byte -> align dest to multiple of 4 movl __RESULT,%edi
.LStrCopyAlignLoop: movl %esi,%edx
movb (%esi),%al movl $1,%ecx
andl $0x0fffffff8,%esi
// skip length byte
incl %edi incl %edi
subl %esi,%edx
jz .LStrPasAligned
movl p,%esi
// align source to multiple of 4 (not dest, because we can't read past
// the end of the source, since that may be past the end of the heap
// -> sigsegv!!)
.LStrPasAlignLoop:
movb (%esi),%al
incl %esi incl %esi
testb %al,%al testb %al,%al
jz .LStrCopyDone jz .LStrPasDone
incb %cl
movb %al,(%edi)
cmpb $4,%cl
jne .LStrCopyAlignLoop
incl %edi incl %edi
.align 16 incb %cl
.LStrCopyAligned: decb %dl
movb %al,-1(%edi)
jne .LStrPasAlignLoop
.balign 16
.LStrPasAligned:
movl (%esi),%eax movl (%esi),%eax
addl $4,%esi addl $4,%esi
// this won't overwrite data since the result = 255 char string // this won't overwrite data since the result = 255 char string
// and we never process more than the first 255 chars of p
movl %eax,(%edi) movl %eax,(%edi)
testl $0x0ff,%eax testl $0x0ff,%eax
jz .LStrCopyDone jz .LStrPasDone
incl %ecx
testl $0x0ff00,%eax testl $0x0ff00,%eax
jz .LStrCopyByte jz .LStrPasDone
incl %ecx
testl $0x0ff0000,%eax testl $0x0ff0000,%eax
jz .LStrCopyWord jz .LStrPasDone
incl %ecx
testl $0x0ff000000,%eax testl $0x0ff000000,%eax
jz .LStrCopy3Bytes jz .LStrPasDone
incl %ecx
addl $4,%edi addl $4,%edi
addb $4,%cl cmpl $252,%ecx
// since ecx = 4 at the start of the loop, it will always count jbe .LStrPasAligned
// upto exactly 0 testb %cl,%cl
jnz .LStrCopyAligned jz .LStrPasDone
jmp .LStrCopyDone movl (%esi),%eax
.LStrCopy3Bytes: .LStrPasEndLoop:
addb $3,%cl testb %al,%al
jmp .LStrCopyDone jz .LStrPasDone
.LStrCopyWord: movb %al,(%edi)
addb $2,%cl shrl $8,%eax
jmp .LStrCopyDone incl %edi
.LStrCopyByte:
incb %cl incb %cl
.LStrCopyDone: jnz .LStrPasEndLoop
.LStrPasDone:
movl __RESULT,%edi movl __RESULT,%edi
addb $255,%cl addb $255,%cl
movb %cl,(%edi) movb %cl,(%edi)
end ['EAX','ECX','ESI','EDI']; end ['EAX','ECX','EDX','ESI','EDI'];
end; end;
function strpcopy(d : pchar;const s : string) : pchar;assembler; function strpcopy(d : pchar;const s : string) : pchar;assembler;
asm asm
pushl %esi // Save ESI pushl %esi // Save ESI
cld cld
movl d,%edi // load destination address
movl s,%esi // Load Source adress movl s,%esi // Load Source adress
lodsb // load length in ECX movl d,%edi // load destination address
movzbl %al,%ecx movzbl (%esi),%ecx // load length in ECX
incl %esi
rep rep
movsb movsb
xorb %al,%al // Set #0 movb $0,(%edi)
stosb
movl d,%eax // return value to EAX movl d,%eax // return value to EAX
popl %esi popl %esi
end ['EDI','EAX','ECX']; end ['EDI','EAX','ECX'];
{ {
$Log$ $Log$
Revision 1.14 2000-06-30 12:20:20 jonas Revision 1.15 2000-07-01 10:52:12 jonas
* fixed reading past end-of-heap again (correctly this time I hope)
Revision 1.14 2000/06/30 12:20:20 jonas
* strpas is again slightly slower, but won't crash anymore if a pchar * strpas is again slightly slower, but won't crash anymore if a pchar
is passed to it that starts less than 4 bbytes from the heap end is passed to it that starts less than 4 bbytes from the heap end