DragonFlyBSD Kernel Audit
DF-1539 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/netif/mn/if_mn.c b/sys/dev/netif/mn/if_mn.c
--- a/sys/dev/netif/mn/if_mn.c
+++ b/sys/dev/netif/mn/if_mn.c
@@ -403,8 +403,20 @@
 			continue;
 		sch = sc->ch[i];
 
-		pos += ksprintf(r + pos, "  Chan %d <%s> ",
-		    i, sch->hook->name);
+		/*
+		 * DF-1539: bound each per-channel emit against the
+		 * remaining NG_TEXTRESPONSE buffer to stop the
+		 * multi-KiB overflow with many open channels.
+		 */
+		{
+			int _n = ksnprintf(r + pos,
+			    NG_TEXTRESPONSE - pos,
+			    "  Chan %d <%s> ",
+			    i, sch->hook->name);
+			if (_n < 0 || _n >= NG_TEXTRESPONSE - pos)
+				break;
+			pos += _n;
+		}
 
 		pos += ksprintf(r + pos, "  Last Rx: ");
 		if (sch->last_recv)
@@ -432,9 +444,15 @@
 		pos += ksprintf(r + pos, " Abort: %lu", sch->abort_error);
 		pos += ksprintf(r + pos, " Overflow: %lu\n", sch->overflow_error);
 
-		pos += ksprintf(r + pos, "    Last error: %pb%i  Prev error: %pb%i\n",
-		    "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN", sch->last_error,
-		    "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN", sch->prev_error);
+		{
+			int _n = ksnprintf(r + pos,
+			    NG_TEXTRESPONSE - pos,
+			    "    Last error: %pb%i  Prev error: %pb%i\n",
+			    "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN", sch->last_error,
+			    "\20\7SHORT\5CRC\4MOD8\3LONG\2ABORT\1OVERRUN", sch->prev_error);
+			if (_n < 0 || _n >= NG_TEXTRESPONSE - pos) break;
+			pos += _n;
+		}
 		pos += ksprintf(r + pos, "    Xmit bytes pending %ld\n",
 		    sch->tx_pending);
 	}