X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fnetconsole.c;h=ce5a15ef57cea6ae378ef2dbd0ca3fbd2122a326;hb=0b8f34dc8cd6a678b26d80152f7bb324bcc15920;hp=e9dbedf32680ec05143e63d70cfa335261fafbf2;hpb=1fdafb2e3dfecdc4129a8062ad25b1adb32b0efb;p=oweals%2Fu-boot.git diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index e9dbedf326..ce5a15ef57 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1,8 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -10,8 +9,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - #ifndef CONFIG_NETCONSOLE_BUFFER_SIZE #define CONFIG_NETCONSOLE_BUFFER_SIZE 512 #endif @@ -153,14 +150,17 @@ int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port, len = sizeof(input_buffer) - input_size; end = input_offset + input_size; - if (end > sizeof(input_buffer)) + if (end >= sizeof(input_buffer)) end -= sizeof(input_buffer); chunk = len; - if (end + len > sizeof(input_buffer)) { + /* Check if packet will wrap in input_buffer */ + if (end + len >= sizeof(input_buffer)) { chunk = sizeof(input_buffer) - end; + /* Copy the second part of the pkt to start of input_buffer */ memcpy(input_buffer, pkt + chunk, len - chunk); } + /* Copy first (or only) part of pkt after end of current valid input*/ memcpy(input_buffer + end, pkt, chunk); input_size += len;