summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-04-21 16:02:28 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-04-21 16:02:28 +0000
commit6e34945379f9b07995c79b0fcf7989879bf18510 (patch)
treece3c9fcd205769b34fa46f8e9e6aee21cab52a68
parentdd740aeffcc208e755bdd398f0d1bb36ea61b5cc (diff)
snprintf error handling, ok beck cloder
-rw-r--r--sys/dev/ic/mpt_debug.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/sys/dev/ic/mpt_debug.c b/sys/dev/ic/mpt_debug.c
index 237ef381562..30c41223ca1 100644
--- a/sys/dev/ic/mpt_debug.c
+++ b/sys/dev/ic/mpt_debug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpt_debug.c,v 1.3 2005/04/17 18:56:35 tom Exp $ */
+/* $OpenBSD: mpt_debug.c,v 1.4 2005/04/21 16:02:27 deraadt Exp $ */
/* $NetBSD: mpt_debug.c,v 1.2 2003/07/14 15:47:11 lukem Exp $ */
/*
@@ -213,12 +213,21 @@ mpt_ioc_diag(u_int32_t code)
static char buf[128];
char *ptr = buf;
char *end = &buf[128];
+ int len;
+
buf[0] = '\0';
- ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
+ len = snprintf(buf, sizeof buf, "(0x%08x)", code);
+ if (len == -1 || len > sizeof buf)
+ return buf;
+ ptr += len;
while (status->Error_Code >= 0) {
- if ((status->Error_Code & code) != 0)
- ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
- status->Error_String);
+ if ((status->Error_Code & code) != 0) {
+ len = snprintf(ptr, (size_t)(end-ptr), "%s ",
+ status->Error_String);
+ if (len == -1 || len > end - ptr)
+ return buf;
+ ptr += len;
+ }
status++;
}
return buf;
@@ -257,12 +266,21 @@ mpt_scsi_state(int code)
static char buf[128];
char *ptr = buf;
char *end = &buf[128];
+ int len;
+
buf[0] = '\0';
- ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
+ len = snprintf(buf, sizeof buf, "(0x%08x)", code);
+ if (len == -1 || len > sizeof buf)
+ return buf;
+ ptr += len;
while (status->Error_Code >= 0) {
- if ((status->Error_Code & code) != 0)
- ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
- status->Error_String);
+ if ((status->Error_Code & code) != 0) {
+ len = snprintf(ptr, (size_t)(end-ptr), "%s ",
+ status->Error_String);
+ if (len == -1 || len > end - ptr)
+ return buf;
+ ptr += len;
+ }
status++;
}
return buf;