From bd78063068b1bf12be6c5c27754de51462c8c37d Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 13 Mar 2002 10:34:47 +0000 Subject: Use the return value from snprintf() to keep a track of the length of the display string in MPPEDispOpts. --- usr.sbin/ppp/ppp/mppe.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/usr.sbin/ppp/ppp/mppe.c b/usr.sbin/ppp/ppp/mppe.c index 1d3b0bfcb6c..41c0de34751 100644 --- a/usr.sbin/ppp/ppp/mppe.c +++ b/usr.sbin/ppp/ppp/mppe.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: mppe.c,v 1.10 2001/09/04 22:12:32 brian Exp $ + * $OpenBSD: mppe.c,v 1.11 2002/03/13 10:34:46 brian Exp $ */ #include @@ -367,40 +367,41 @@ MPPEDispOpts(struct lcp_opt *o) static char buf[70]; u_int32_t val; char ch; - int len; + int len, n; ua_ntohl(o->data, &val); - snprintf(buf, sizeof buf, "value 0x%08x ", (unsigned)val); - len = strlen(buf); + len = 0; + if ((n = snprintf(buf, sizeof buf, "value 0x%08x ", (unsigned)val)) > 0) + len += n; if (!(val & MPPE_OPT_BITMASK)) { - snprintf(buf + len, sizeof buf - len, "(0"); - len++; + if ((n = snprintf(buf + len, sizeof buf - len, "(0")) > 0) + len += n; } else { ch = '('; if (val & MPPE_OPT_128BIT) { - snprintf(buf + len, sizeof buf - len, "%c128", ch); - len += strlen(buf + len); + if ((n = snprintf(buf + len, sizeof buf - len, "%c128", ch)) > 0) + len += n; ch = '/'; } if (val & MPPE_OPT_56BIT) { - snprintf(buf + len, sizeof buf - len, "%c56", ch); - len += strlen(buf + len); + if ((n = snprintf(buf + len, sizeof buf - len, "%c56", ch)) > 0) + len += n; ch = '/'; } if (val & MPPE_OPT_40BIT) { - snprintf(buf + len, sizeof buf - len, "%c40", ch); - len += strlen(buf + len); + if ((n = snprintf(buf + len, sizeof buf - len, "%c40", ch)) > 0) + len += n; ch = '/'; } } - snprintf(buf + len, sizeof buf - len, " bits, state%s", - (val & MPPE_OPT_STATELESS) ? "less" : "ful"); - len += strlen(buf + len); + if ((n = snprintf(buf + len, sizeof buf - len, " bits, state%s", + (val & MPPE_OPT_STATELESS) ? "less" : "ful")) > 0) + len += n; if (val & MPPE_OPT_COMPRESSED) { - snprintf(buf + len, sizeof buf - len, ", compressed"); - len += strlen(buf + len); + if ((n = snprintf(buf + len, sizeof buf - len, ", compressed")) > 0) + len += n; } snprintf(buf + len, sizeof buf - len, ")"); -- cgit v1.2.3