From eb7e44a0e0439af9a3e3272ee2988d0371a6dd5f Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Tue, 5 Mar 2024 09:49:00 +0000 Subject: [PATCH] Fixed bug when parsing JOIN command. Implemented proper handeling of partially received commands. git-svn-id: svn://kolibrios.org@9984 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/network/ircc/ircc.asm | 4 +++- programs/network/ircc/serverparser.inc | 23 ++++++++++++++--------- programs/network/ircc/socket.inc | 18 +++++++++++------- programs/network/ircc/users.inc | 6 +++++- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/programs/network/ircc/ircc.asm b/programs/network/ircc/ircc.asm index bda27bd0a0..7066b191f1 100644 --- a/programs/network/ircc/ircc.asm +++ b/programs/network/ircc/ircc.asm @@ -13,7 +13,7 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -version equ '0.35c' +version equ '0.36' ; connection status STATUS_DISCONNECTED = 0 @@ -572,6 +572,8 @@ status dd STATUS_DISCONNECTED window_active dd windows window_print dd windows +cmd_remaining dd 0 + align 4 @IMPORT: diff --git a/programs/network/ircc/serverparser.inc b/programs/network/ircc/serverparser.inc index 926e105f49..587b8bfecc 100644 --- a/programs/network/ircc/serverparser.inc +++ b/programs/network/ircc/serverparser.inc @@ -548,6 +548,10 @@ cmd_part: cmp byte [esi+4], ' ' jne .fail add esi, 5 ; skip 'PART ' + cmp byte[esi], ':' + jne @f + inc esi + @@: ; Is it me who parted? mov edi, servercommand+1 @@ -610,6 +614,10 @@ cmd_join: cmp byte[esi+4], ' ' jne .fail add esi, 5 ; skip 'JOIN ' + cmp byte[esi], ':' + jne @f + inc esi + @@: ; did we join a channel? mov edi, servercommand+1 @@ -982,22 +990,19 @@ cmd_353: ; channel usernames reply ; TODO: remove all users? .add: - push esi - call user_add - pop esi - - .namesloop: lodsb test al, al jz .done - cmp al, ' ' ; names list is separated with spaces - jne .namesloop + cmp al, ' ' + je .add + dec esi + call user_add jmp .add .done: call draw_user_list - .fail: + .fail: ret @@ -1108,4 +1113,4 @@ cmd_322: ; LIST cmd_323: ; LIST END - ret \ No newline at end of file + ret diff --git a/programs/network/ircc/socket.inc b/programs/network/ircc/socket.inc index 79af9217df..2da60a5fa7 100644 --- a/programs/network/ircc/socket.inc +++ b/programs/network/ircc/socket.inc @@ -210,10 +210,8 @@ socket_receive: pusha -; FIXME: make this a proper stream! - - .nextpacket: - mcall recv, [socketnum], packetbuf, PACKETBUF_SIZE, MSG_DONTWAIT ; read a packet + .recv_more: + mcall recv, [socketnum], packetbuf , PACKETBUF_SIZE, MSG_DONTWAIT ; read a packet inc eax ; check if we got any data jz .done ; TODO: handle errors! dec eax @@ -223,17 +221,19 @@ socket_receive: mov ecx, eax mov esi, packetbuf ; esi = start pointer - .nextcommand: mov edi, servercommand + add edi, [cmd_remaining] .byteloop: test ecx, ecx - jz .nextpacket + jz .recv_more lodsb dec ecx cmp al, 10 je .got_command cmp al, 13 je .got_command + cmp edi, servercommand + SERVERCOMMAND_SIZE ; Prevent command buffer overflow + jae .byteloop stosb jmp .byteloop @@ -249,7 +249,11 @@ socket_receive: sub ecx, servercommand ; put length in ecx call server_parser pop ecx esi - jmp .nextcommand + + .nextcommand: + mov edi, servercommand + mov [cmd_remaining], ecx ; remaining bytes since last EOL + jmp .byteloop .done: popa diff --git a/programs/network/ircc/users.inc b/programs/network/ircc/users.inc index 9806cedf71..1bcb7f3841 100644 --- a/programs/network/ircc/users.inc +++ b/programs/network/ircc/users.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; @@ -24,6 +24,7 @@ user_add: cmp [ebx + window.users], MAX_USERS jae .fail +; Check if user is already listed (case insensitive) mov edi, [ebx + window.data_ptr] add edi, window_data.names mov ebp, [ebx + window.users] @@ -107,6 +108,8 @@ user_add: je .done cmp al, 10 je .done + cmp al, 0 + je .done stosb loop .fill .done: @@ -115,6 +118,7 @@ user_add: inc [ebx + window.users] or [ebx + window.flags], FLAG_UPDATED + dec esi .fail: ret