From c5afc922980dd19c1da1ac0c05064ce95c977749 Mon Sep 17 00:00:00 2001 From: Marian Marinov Date: Mon, 1 Apr 2024 22:25:15 -0400 Subject: [PATCH 1/4] rtt.c: Fix misleading indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the following compilation warning: rtt.c: In function ‘rtt’: rtt.c:43:17: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] 43 | for (i=0; i --- rtt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtt.c b/rtt.c index e06343d..57fc309 100644 --- a/rtt.c +++ b/rtt.c @@ -45,8 +45,8 @@ int rtt(int *seqp, int recvport, float *ms_delay) tablepos = i; break; } - if (i != TABLESIZE) - *seqp = delaytable[i].seq; + if (i != TABLESIZE) + *seqp = delaytable[i].seq; } if (tablepos != -1) From dbb8d912d637fd6de37a2d62ea55b6596ff701ea Mon Sep 17 00:00:00 2001 From: Marian Marinov Date: Mon, 1 Apr 2024 22:32:17 -0400 Subject: [PATCH 2/4] listen.c: Fix compilation error. Handle the output of write() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the following compilation warning: listen.c: In function ‘listenmain’: listen.c:77:25: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 77 | write(stdoutFD, p, size-(p-ip_packet)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Marian Marinov --- listen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/listen.c b/listen.c index 2a73c43..4f18b80 100644 --- a/listen.c +++ b/listen.c @@ -27,6 +27,7 @@ void listenmain(void) int stdoutFD = fileno(stdout); char packet[IP_MAX_SIZE+linkhdr_size]; char *p, *ip_packet; + ssize_t bytes_written; struct myiphdr ip; __u16 id; static __u16 exp_id; /* expected id */ @@ -74,7 +75,9 @@ void listenmain(void) } p+=strlen(sign); - write(stdoutFD, p, size-(p-ip_packet)); + bytes_written = write(stdoutFD, p, size-(p-ip_packet)); + if (bytes_written == -1) + fprintf(stderr, "Unable to send packet\n"); } } } From e38e30a7071b7f06b0dc3175f0900f01ab0a3ff1 Mon Sep 17 00:00:00 2001 From: Marian Marinov Date: Mon, 1 Apr 2024 22:46:49 -0400 Subject: [PATCH 3/4] sendicmp.c: Fix compilation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the following compilation warning: gcc -c -O2 -Wall -g sendicmp.c In file included from /usr/include/string.h:535, from sendicmp.c:19: In function ‘memcpy’, inlined from ‘send_icmp_other’ at sendicmp.c:256:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:10: warning: ‘__builtin_memcpy’ forming offset [20, 27] is out of the bounds [0, 20] of object ‘icmp_ip’ with type ‘struct myiphdr’ [-Warray-bounds] 29 | return __builtin___memcpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ sendicmp.c: In function ‘send_icmp_other’: sendicmp.c:197:24: note: ‘icmp_ip’ declared here 197 | struct myiphdr icmp_ip; | ^~~~~~~ Copying out of bounds may result in nasty security exploits. --- sendicmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendicmp.c b/sendicmp.c index 7efb274..ed4968b 100644 --- a/sendicmp.c +++ b/sendicmp.c @@ -253,7 +253,7 @@ void send_icmp_other(void) /* fill IP */ if (left_space == 0) goto no_space_left; - memcpy(packet+ICMPHDR_SIZE, &icmp_ip, left_space); + memcpy(packet+ICMPHDR_SIZE, &icmp_ip, ICMPHDR_SIZE); left_space -= IPHDR_SIZE; data += IPHDR_SIZE; if (left_space <= 0) goto no_space_left; From 40768267f9ee7ad2430d7549440a761d8e038c43 Mon Sep 17 00:00:00 2001 From: Marian Marinov Date: Mon, 1 Apr 2024 22:50:12 -0400 Subject: [PATCH 4/4] gethostname.c: Fix compilation warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit proposes a fix for the following compilation warning. The warning is reported, because the string is initialized with NULL values, but the strncpy() is overwriting the full length of the string, which actually overwrites the last NULL value too. In file included from /usr/include/string.h:535, from gethostname.c:19: In function ‘strncpy’, inlined from ‘get_hostname’ at gethostname.c:37:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘strncpy’, inlined from ‘get_hostname’ at gethostname.c:46:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ --- gethostname.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gethostname.c b/gethostname.c index 97015ef..1646843 100644 --- a/gethostname.c +++ b/gethostname.c @@ -34,7 +34,7 @@ char *get_hostname(char* addr) if (!strcmp(addr, lastreq)) return last_answerp; - strncpy(lastreq, addr, 1024); + strncpy(lastreq, addr, 1023); inet_aton(addr, &naddr); he = gethostbyaddr((char*)&naddr, 4, AF_INET); @@ -43,7 +43,7 @@ char *get_hostname(char* addr) return NULL; } - strncpy(answer, he->h_name, 1024); + strncpy(answer, he->h_name, 1023); last_answerp = answer; return answer;