From f105b9cfdf7397aff425370d2ee9838ef5c0b63d Mon Sep 17 00:00:00 2001 From: nisargshah95 Date: Sat, 28 May 2016 10:18:22 +0000 Subject: [PATCH] add proper error handling for socket functions git-svn-id: svn://kolibrios.org@6437 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/network/ftpc/parser.inc | 42 +++++++++++++++--------- programs/network/ftpc/servercommands.inc | 12 ++++--- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/programs/network/ftpc/parser.inc b/programs/network/ftpc/parser.inc index accad20708..6c8a1a60a8 100644 --- a/programs/network/ftpc/parser.inc +++ b/programs/network/ftpc/parser.inc @@ -29,8 +29,10 @@ resolve: .user: lodsb cmp al, 0 - je .error - stosb + jne @f + mov eax, str_err_params + jmp error + @@: stosb cmp byte [esi], ':' jne .user mov word [edi], 0x0a0d @@ -44,8 +46,10 @@ resolve: .pass: lodsb cmp al, 0 - je .error - stosb + jne @f + mov eax, str_err_params + jmp error + @@: stosb cmp byte [esi], '@' jne .pass mov word [edi], 0x0a0d @@ -57,8 +61,10 @@ resolve: .addr: lodsb cmp al, 0 - je .error - stosb + jne @f + mov eax, str_err_params + jmp error + @@: stosb cmp byte [esi], ':' jne .addr mov byte [edi], 0 @@ -71,18 +77,24 @@ resolve: .port: lodsb cmp al, 0 - je .error - cmp al, '/' - jbe @f + jne @f + mov eax, str_err_params + jmp error + @@: cmp al, '/' + jbe .port_done sub al, '0' - jb error_hostname - cmp al, 9 - ja error_hostname - lea ebx, [ebx*4 + ebx] + jnb @f + mov eax, str_err_host + jmp error + @@: cmp al, 9 + jna @f + mov eax, str_err_host + jmp error + @@: lea ebx, [ebx*4 + ebx] shl ebx, 1 add ebx, eax jmp .port - @@: ; port done + .port_done: xchg bl, bh mov [sockaddr1.port], bx @@ -112,5 +124,3 @@ resolve: jmp no_resolve.done - .error: - jmp main ; parameter resolution failed. get input from user \ No newline at end of file diff --git a/programs/network/ftpc/servercommands.inc b/programs/network/ftpc/servercommands.inc index 093eccc0ce..45e6d8a98c 100644 --- a/programs/network/ftpc/servercommands.inc +++ b/programs/network/ftpc/servercommands.inc @@ -84,8 +84,10 @@ pasv_ok: mcall socket, AF_INET4, SOCK_STREAM, 0 cmp eax, -1 - je error_socket - mov [datasocket], eax + jne @f + mov eax, str_err_socket + jmp error + @@: mov [datasocket], eax mov esi, edi call ascii_dec @@ -105,8 +107,10 @@ pasv_ok: invoke con_write_asciiz, str_open mcall connect, [datasocket], sockaddr2, 18 cmp eax, -1 - je error_socket - jmp wait_for_servercommand + jne @f + mov eax, str_err_connect + jmp error + @@: jmp wait_for_servercommand .fail: invoke con_write_asciiz, str_unknown