All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ax25-tools: mheard
@ 2016-07-17 14:53 Guido Trentalancia
  2016-07-17 18:29 ` Thomas Osterried
  0 siblings, 1 reply; 6+ messages in thread
From: Guido Trentalancia @ 2016-07-17 14:53 UTC (permalink / raw)
  To: linux-hams

The following patch prevents fatal segmentation faults errors
on strcpy() in the mheard tool when the result of ctime() is
zero and it also avoids printing inconsistent log entries.

Signed-off-by: Guido Trentalancia <iz6rdb@trentalancia.net>
---
 ax25/mheard.c |   39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

--- ax25-tools-0.0.10-rc2-orig/ax25/mheard.c	2016-07-17 16:15:14.810986323 +0200
+++ ax25-tools-0.0.10-rc2/ax25/mheard.c	2016-07-17 16:14:15.332363054 +0200
@@ -57,27 +57,39 @@ static void PrintHeader(int data)
 
 static void PrintPortEntry(struct PortRecord *pr, int data)
 {
-	char lh[30], fh[30], *call, *s;
+	char lh[30], fh[30], *call, *s, *ctime_out;
 	char buffer[80];
-	int i;
+	int i, pkt_count;
 
 	switch (data) {
 		case 0:
-			strcpy(lh, ctime(&pr->entry.last_heard));
+			ctime_out = ctime(&pr->entry.last_heard);
+			if (!ctime_out)
+				break;
+			strcpy(lh, ctime_out);
 			lh[19] = 0;
 			call =  ax25_ntoa(&pr->entry.from_call);
+			if (!call)
+				break;
 			if ((s = strstr(call, "-0")) != NULL)
 				*s = '\0';
+			pkt_count = pr->entry.count;
+			if (!pkt_count)
+				break;
 			printf("%-10s %-5s %5d   %s\n",
-				call, pr->entry.portname, pr->entry.count, lh);
+				call, pr->entry.portname, pkt_count, lh);
 			break;
 		case 1:
 			buffer[0] = '\0';
 			call = ax25_ntoa(&pr->entry.from_call);
+			if (!call)
+				break;
 			if ((s = strstr(call, "-0")) != NULL)
 				*s = '\0';
 			strcat(buffer, call);
 			call = ax25_ntoa(&pr->entry.to_call);
+			if (!call)
+				break;
 			if ((s = strstr(call, "-0")) != NULL)
 				*s = '\0';
 			strcat(buffer, ">");
@@ -95,11 +107,19 @@ static void PrintPortEntry(struct PortRe
 				buffer, pr->entry.portname);
 			break;
 		case 2:
-			strcpy(lh, ctime(&pr->entry.last_heard));
+			ctime_out = ctime(&pr->entry.last_heard);
+			if (!ctime_out)
+				break;
+			strcpy(lh, ctime_out);
 			lh[19] = 0;
-			strcpy(fh, ctime(&pr->entry.first_heard));
+			ctime_out = ctime(&pr->entry.first_heard);
+			if (!ctime_out)
+				break;
+			strcpy(fh, ctime_out);
 			fh[19] = 0;
 			call = ax25_ntoa(&pr->entry.from_call);
+			if (!call)
+				break;
 			if ((s = strstr(call, "-0")) != NULL)
 				*s = '\0';
 			printf("%-10s %-5s %5d %5d %5d  %s  %s\n",
@@ -107,10 +127,15 @@ static void PrintPortEntry(struct PortRe
 			break;
 		case 3:
 			call = ax25_ntoa(&pr->entry.from_call);
+			if (!call)
+				break;
 			if ((s = strstr(call, "-0")) != NULL)
 				*s = '\0';
+			pkt_count = pr->entry.count;
+			if (!pkt_count)
+				break;
 			printf("%-10s %-5s %5d %5s ",
-				call, pr->entry.portname, pr->entry.count, types[pr->entry.type]);
+				call, pr->entry.portname, pkt_count, types[pr->entry.type]);
 			if (pr->entry.mode & MHEARD_MODE_ARP)
 				printf(" ARP");
 			if (pr->entry.mode & MHEARD_MODE_FLEXNET)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-07-18 15:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-17 14:53 [PATCH] ax25-tools: mheard Guido Trentalancia
2016-07-17 18:29 ` Thomas Osterried
2016-07-17 20:14   ` [PATCH v2] " Guido Trentalancia
2016-07-18 14:25     ` walter harms
2016-07-18 15:50       ` Thomas Osterried
2016-07-18 15:58         ` walter harms

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.