Module Name: src Committed By: tls Date: Mon Aug 30 19:23:26 UTC 2010
Modified Files: src/sys/ddb: db_input.c Log Message: Don't overflow DDB command history. Coyote Point changelist description: DDB is flakey. The command history wanders past the bounds. Way past. When it hits some boolean that indicates a.out format symbol tables are to be used, and here is the pointer to the function, the call thru the NULL function pointer renders the debug session entirely unsatisfactory, outcome wise. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/ddb/db_input.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/ddb/db_input.c diff -u src/sys/ddb/db_input.c:1.23 src/sys/ddb/db_input.c:1.24 --- src/sys/ddb/db_input.c:1.23 Sat Mar 7 22:02:17 2009 +++ src/sys/ddb/db_input.c Mon Aug 30 19:23:25 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: db_input.c,v 1.23 2009/03/07 22:02:17 ad Exp $ */ +/* $NetBSD: db_input.c,v 1.24 2010/08/30 19:23:25 tls Exp $ */ /* * Mach Operating System @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_input.c,v 1.23 2009/03/07 22:02:17 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_input.c,v 1.24 2010/08/30 19:23:25 tls Exp $"); #ifdef _KERNEL_OPT #include "opt_ddbparam.h" @@ -63,7 +63,6 @@ static char *db_le; /* one past last character */ #if DDB_HISTORY_SIZE != 0 static char db_history[DDB_HISTORY_SIZE]; /* start of history buffer */ -static int db_history_size = DDB_HISTORY_SIZE;/* size of history buffer */ static char *db_history_curr = db_history; /* start of current line */ static char *db_history_last = db_history; /* start of last line */ static char *db_history_prev = (char *) 0; /* start of previous line */ @@ -131,21 +130,31 @@ } #if DDB_HISTORY_SIZE != 0 -#define INC_DB_CURR() \ - do { \ - db_history_curr++; \ - if (db_history_curr > db_history + db_history_size - 1) \ - db_history_curr = db_history; \ - } while (/*CONSTCOND*/ 0) -#define DEC_DB_CURR() \ - do { \ - db_history_curr--; \ - if (db_history_curr < db_history) \ - db_history_curr = db_history + \ - db_history_size - 1; \ - } while (/*CONSTCOND*/ 0) + +#define INC_DB_CURR() do { \ + ++db_history_curr; \ + if (db_history_curr > db_history + DDB_HISTORY_SIZE - 1) \ + db_history_curr = db_history; \ + } while (0) +#define DEC_DB_CURR() do { \ + --db_history_curr; \ + if (db_history_curr < db_history) \ + db_history_curr = db_history + DDB_HISTORY_SIZE - 1; \ + } while (0) #endif +static inline void db_hist_put(int c) +{ + KASSERT(&db_history[0] <= db_history_last); + KASSERT(db_history_last <= &db_history[DDB_HISTORY_SIZE-1]); + + *db_history_last++ = c; + + if (db_history_last > &db_history[DDB_HISTORY_SIZE-1]) + db_history_last = db_history; +} + + /* returns true at end-of-line */ static int db_inputchar(int c) @@ -239,7 +248,7 @@ for (p = db_history_curr, db_le = db_lbuf_start; *p; ) { *db_le++ = *p++; - if (p == db_history + db_history_size) { + if (p >= db_history + DDB_HISTORY_SIZE) { p = db_history; } } @@ -261,8 +270,7 @@ for (p = db_history_curr, db_le = db_lbuf_start; *p;) { *db_le++ = *p++; - if (p == db_history + - db_history_size) { + if (p >= db_history + DDB_HISTORY_SIZE) { p = db_history; } } @@ -291,10 +299,10 @@ pc != db_le && *pp; pp++, pc++) { if (*pp != *pc) break; - if (++pp == db_history + db_history_size) { + if (++pp >= db_history + DDB_HISTORY_SIZE) { pp = db_history; } - if (++pc == db_history + db_history_size) { + if (++pc >= db_history + DDB_HISTORY_SIZE) { pc = db_history; } } @@ -307,15 +315,13 @@ } if (db_le != db_lbuf_start) { char *p; + db_history_prev = db_history_last; - for (p = db_lbuf_start; p != db_le; p++) { - *db_history_last++ = *p; - if (db_history_last == db_history + - db_history_size) { - db_history_last = db_history; - } + + for (p = db_lbuf_start; p != db_le; ) { + db_hist_put(*p++); } - *db_history_last++ = '\0'; + db_hist_put(0); } db_history_curr = db_history_last; #endif