HTTP_escape, HTTP_unescape, check for end of buffer.

git-svn-id: svn://kolibrios.org@7101 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2017-10-17 21:18:36 +00:00
parent 5c83dd9e7c
commit 909a57ee08

View File

@ -1296,6 +1296,7 @@ proc HTTP_escape URI, length ;//////////////////////////////////////////////////
invoke mem.alloc, URLMAXLEN ; FIXME: use length provided by caller to guess final size. invoke mem.alloc, URLMAXLEN ; FIXME: use length provided by caller to guess final size.
test eax, eax test eax, eax
jz .error jz .error
mov edx, URLMAXLEN-1 ; Remaining space in temp buffer minus one for 0 byte
mov [esp + 7 * 4], eax ; return ptr in eax mov [esp + 7 * 4], eax ; return ptr in eax
mov esi, [URI] mov esi, [URI]
mov edi, eax mov edi, eax
@ -1315,9 +1316,13 @@ proc HTTP_escape URI, length ;//////////////////////////////////////////////////
jc .escape jc .escape
stosb stosb
jmp .loop dec edx
jnz .loop
jmp .out_of_space
.escape: .escape:
sub edx, 3
jbe .out_of_space
mov al, '%' mov al, '%'
stosb stosb
mov bl, byte[esi-1] mov bl, byte[esi-1]
@ -1331,7 +1336,11 @@ proc HTTP_escape URI, length ;//////////////////////////////////////////////////
jmp .loop jmp .loop
.out_of_space:
DEBUGF 2, "ERROR: buffer too small!\n"
.done: .done:
xor al, al
stosb stosb
sub edi, [esp + 7 * 4] sub edi, [esp + 7 * 4]
dec edi dec edi
@ -1367,6 +1376,7 @@ proc HTTP_unescape URI, length ;////////////////////////////////////////////////
invoke mem.alloc, URLMAXLEN ; FIXME: use length provided by caller invoke mem.alloc, URLMAXLEN ; FIXME: use length provided by caller
test eax, eax test eax, eax
jz .error jz .error
mov edx, URLMAXLEN-1 ; Remaining space in temp buffer minus one for 0 byte
mov [esp + 7 * 4], eax ; return ptr in eax mov [esp + 7 * 4], eax ; return ptr in eax
mov esi, [URI] mov esi, [URI]
mov edi, eax mov edi, eax
@ -1377,7 +1387,9 @@ proc HTTP_unescape URI, length ;////////////////////////////////////////////////
cmp al, '%' cmp al, '%'
je .unescape je .unescape
stosb stosb
jmp .loop dec edx
jnz .loop
jmp .out_of_space
.unescape: .unescape:
xor ebx, ebx xor ebx, ebx
@ -1402,13 +1414,19 @@ proc HTTP_unescape URI, length ;////////////////////////////////////////////////
jc .unescape_nibble jc .unescape_nibble
mov al, bl mov al, bl
stosb stosb
jmp .loop dec edx
jnz .loop
jmp .out_of_space
.fail: .fail:
DEBUGF 2, "ERROR: invalid URI!\n" DEBUGF 2, "ERROR: invalid URI!\n"
jmp .loop jmp .loop
.out_of_space:
DEBUGF 2, "ERROR: buffer too small!\n"
.done: .done:
xor al, al
stosb stosb
popa popa
DEBUGF 1, "unescaped URL: %s\n", eax DEBUGF 1, "unescaped URL: %s\n", eax