diff options
author | Niels Provos <provos@cvs.openbsd.org> | 2001-06-24 22:24:01 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 2001-06-24 22:24:01 +0000 |
commit | 8ac5f4f8392786d9a55a48994415b7d6828b1a10 (patch) | |
tree | 1293cc92f64cd1e6fe185dfd149ae97e504b151b | |
parent | 67b463b6949b5f1d47e52c6298880e51d9f98b03 (diff) |
prevent buffer overflow
-rw-r--r-- | sbin/wicontrol/wicontrol.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sbin/wicontrol/wicontrol.c b/sbin/wicontrol/wicontrol.c index dc44c29b1ba..54c7ce14e7f 100644 --- a/sbin/wicontrol/wicontrol.c +++ b/sbin/wicontrol/wicontrol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wicontrol.c,v 1.16 2001/06/24 01:58:13 marc Exp $ */ +/* $OpenBSD: wicontrol.c,v 1.17 2001/06/24 22:24:00 provos Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -67,7 +67,7 @@ static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\ Bill Paul. All rights reserved."; static const char rcsid[] = - "@(#) $OpenBSD: wicontrol.c,v 1.16 2001/06/24 01:58:13 marc Exp $"; + "@(#) $OpenBSD: wicontrol.c,v 1.17 2001/06/24 22:24:00 provos Exp $"; #endif static void wi_getval __P((char *, struct wi_req *)); @@ -140,11 +140,12 @@ wi_printstr(wreq) struct wi_req *wreq; { char *ptr; - int i; + int i, max; if (wreq->wi_type == WI_RID_SERIALNO) { ptr = (char *)&wreq->wi_val; - for (i = 0; i < (wreq->wi_len - 1) * 2; i++) { + max = MIN(sizeof(wreq->wi_val) - 1, (wreq->wi_len - 1) * 2); + for (i = 0; i < max; i++) { if (ptr[i] == '\0') ptr[i] = ' '; } @@ -152,7 +153,8 @@ wi_printstr(wreq) int len = letoh16(wreq->wi_val[0]); ptr = (char *)&wreq->wi_val[1]; - for (i = 0; i < len; i++) { + max = MIN(sizeof(wreq->wi_val) - 1, len); + for (i = 0; i < max; i++) { if (ptr[i] == '\0') ptr[i] = ' '; } |