diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 2002-07-30 05:27:50 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 2002-07-30 05:27:50 +0000 |
commit | e6f7bd2256b4a652c665aa93ed855cdb959cd76c (patch) | |
tree | bc7f5f5a8f3c4bb514ed2e2880d42c4735e5475b | |
parent | bba59a542f4e14d19d8a4a1ffbbab36c42ce2fe7 (diff) |
Kill buffer overflow.
-rw-r--r-- | games/backgammon/common_source/back.h | 6 | ||||
-rw-r--r-- | games/backgammon/common_source/init.c | 7 | ||||
-rw-r--r-- | games/backgammon/common_source/table.c | 19 |
3 files changed, 19 insertions, 13 deletions
diff --git a/games/backgammon/common_source/back.h b/games/backgammon/common_source/back.h index 9588693c272..21234101ed2 100644 --- a/games/backgammon/common_source/back.h +++ b/games/backgammon/common_source/back.h @@ -1,4 +1,4 @@ -/* $OpenBSD: back.h,v 1.7 2002/02/16 21:27:08 millert Exp $ */ +/* $OpenBSD: back.h,v 1.8 2002/07/30 05:27:49 pjanzen Exp $ */ /* * Copyright (c) 1980, 1993 @@ -51,6 +51,8 @@ #define D0 dice[0] #define D1 dice[1] #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;} + +#define CIN_SIZE 40 #ifdef DEBUG extern FILE *trace; @@ -118,7 +120,7 @@ extern int *inptr; /* pointer to in for current player */ extern int *inopp; /* pointer to in for opponent */ extern int ncin; /* number of characters in cin */ -extern char cin[100]; /* input line of current move +extern char cin[CIN_SIZE]; /* input line of current move (used for reconstructing input after a backspace) */ diff --git a/games/backgammon/common_source/init.c b/games/backgammon/common_source/init.c index 88f2dea2fd5..ca3e2c8cf7a 100644 --- a/games/backgammon/common_source/init.c +++ b/games/backgammon/common_source/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $ */ +/* $OpenBSD: init.c,v 1.6 2002/07/30 05:27:49 pjanzen Exp $ */ /* * Copyright (c) 1980, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: init.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: init.c,v 1.6 2002/07/30 05:27:49 pjanzen Exp $"; #endif #endif /* not lint */ @@ -49,6 +49,7 @@ static char rcsid[] = "$OpenBSD: init.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $" #include <stdio.h> FILE *trace; #endif +#include <back.h> /* name of executable object programs */ const char EXEC[] = "/usr/games/backgammon"; @@ -82,7 +83,7 @@ char args[100]; int bar; int begscr; int board[26]; -char cin[100]; +char cin[CIN_SIZE]; int colen; int cturn; int d0; diff --git a/games/backgammon/common_source/table.c b/games/backgammon/common_source/table.c index 3d9addc8d31..167c34f524e 100644 --- a/games/backgammon/common_source/table.c +++ b/games/backgammon/common_source/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.4 2001/06/23 23:50:04 pjanzen Exp $ */ +/* $OpenBSD: table.c,v 1.5 2002/07/30 05:27:49 pjanzen Exp $ */ /* * Copyright (c) 1980, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: table.c,v 1.4 2001/06/23 23:50:04 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: table.c,v 1.5 2002/07/30 05:27:49 pjanzen Exp $"; #endif #endif /* not lint */ @@ -118,16 +118,19 @@ dochar: } if ((ist = n) > 0) goto dochar; + getyx(stdscr, curr, curc); + move(curr, 39); + clrtoeol(); goto domove; - } - if (c == KEY_DL && ncin > 0) { - refresh(); + } else if (c == KEY_DL && ncin > 0) { getyx(stdscr, curr, curc); move(curr, 39); + clrtoeol(); ist = -1; + refresh(); goto domove; } - if (!isascii(c)) { + if (!isascii(c) || (ncin >= CIN_SIZE - 1)) { beep(); goto domove; } @@ -135,8 +138,8 @@ dochar: if (n >= 0) { cin[ncin++] = c; if (n > 2) - if (c != '\n') - addch(c); + if (c != '\n') + addch(c); ist = n; if (n) goto dochar; |