diff options
-rw-r--r-- | sbin/isakmpd/math_2n.c | 10 | ||||
-rw-r--r-- | sbin/isakmpd/math_2n.h | 4 | ||||
-rw-r--r-- | sbin/isakmpd/regress/b2n/b2ntest.c | 10 | ||||
-rw-r--r-- | sbin/isakmpd/regress/ec2n/ec2ntest.c | 8 |
4 files changed, 18 insertions, 14 deletions
diff --git a/sbin/isakmpd/math_2n.c b/sbin/isakmpd/math_2n.c index 2a59ee0ef17..853388517a7 100644 --- a/sbin/isakmpd/math_2n.c +++ b/sbin/isakmpd/math_2n.c @@ -1,4 +1,4 @@ -/* $OpenBSD: math_2n.c,v 1.8 2001/04/09 22:09:52 ho Exp $ */ +/* $OpenBSD: math_2n.c,v 1.9 2002/01/23 17:43:24 ho Exp $ */ /* $EOM: math_2n.c,v 1.15 1999/04/20 09:23:30 niklas Exp $ */ /* @@ -276,7 +276,7 @@ b2n_print (b2n_ptr n) } int -b2n_sprint (char *buf, b2n_ptr n) +b2n_snprint (char *buf, size_t sz, b2n_ptr n) { int i, k, j, w, flag = 0; int left; @@ -285,8 +285,8 @@ b2n_sprint (char *buf, b2n_ptr n) left = ((((7 + b2n_sigbit (n)) >> 3) - 1) % CHUNK_BYTES) + 1; - strcpy (buf, "0x"); k = 2; - for (i = 0; i < n->chunks; i++) + k = strlcpy (buf, "0x", sz); + for (i = 0; i < n->chunks && k < sz - 1; i++) { tmp = n->limp[n->chunks - 1 - i]; memset (buffer, '0', sizeof (buffer)); @@ -297,7 +297,7 @@ b2n_sprint (char *buf, b2n_ptr n) tmp >>= 8; } - for (j = (i == 0 ? left - 1: CHUNK_BYTES - 1); j >= 0; j--) + for (j = (i == 0 ? left - 1: CHUNK_BYTES - 1); j >= 0 && k < sz - 3; j--) if (flag || (i == n->chunks - 1 && j == 0) || buffer[2 * j] != '0' || buffer[2 * j + 1] != '0') { diff --git a/sbin/isakmpd/math_2n.h b/sbin/isakmpd/math_2n.h index 93f21cda946..eebcb401bb8 100644 --- a/sbin/isakmpd/math_2n.h +++ b/sbin/isakmpd/math_2n.h @@ -1,4 +1,4 @@ -/* $OpenBSD: math_2n.h,v 1.4 1999/04/19 19:56:23 niklas Exp $ */ +/* $OpenBSD: math_2n.h,v 1.5 2002/01/23 17:43:24 ho Exp $ */ /* $EOM: math_2n.h,v 1.9 1999/04/17 23:20:32 niklas Exp $ */ /* @@ -128,7 +128,7 @@ int b2n_set_null (b2n_ptr); int b2n_set_str (b2n_ptr, char *); int b2n_set_ui (b2n_ptr, unsigned int); u_int32_t b2n_sigbit (b2n_ptr); -int b2n_sprint (char *, b2n_ptr); +int b2n_snprint (char *, size_t, b2n_ptr); int b2n_sqrt (b2n_ptr, b2n_ptr, b2n_ptr); int b2n_square (b2n_ptr, b2n_ptr); #define b2n_sub b2n_add diff --git a/sbin/isakmpd/regress/b2n/b2ntest.c b/sbin/isakmpd/regress/b2n/b2ntest.c index 66a7241aeec..f8e985c81a8 100644 --- a/sbin/isakmpd/regress/b2n/b2ntest.c +++ b/sbin/isakmpd/regress/b2n/b2ntest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b2ntest.c,v 1.5 2001/01/27 12:03:37 niklas Exp $ */ +/* $OpenBSD: b2ntest.c,v 1.6 2002/01/23 17:43:24 ho Exp $ */ /* $EOM: b2ntest.c,v 1.4 1998/07/16 19:31:55 provos Exp $ */ /* @@ -47,7 +47,9 @@ #include "math_2n.h" -#define CMP_FAIL(n,x) b2n_sprint (buf, n); if (strcmp (buf, (x))) \ +#define BUFSIZE 200 + +#define CMP_FAIL(n,x) b2n_snprint (buf, BUFSIZE, n); if (strcmp (buf, (x))) \ printf ("FAILED: %s != %s ", buf, x); else printf ("OKAY "); int @@ -55,7 +57,7 @@ main (void) { int i; b2n_t n, m, d, r; - char buf[200]; + char buf[BUFSIZE]; b2n_init (n); b2n_init (m); @@ -273,7 +275,7 @@ main (void) printf ("\nTesting: b2n_random: "); b2n_random (m, 155); - b2n_sprint (buf, m); + b2n_snprint (buf, BUFSIZE, m); printf ("%s, %d", buf, b2n_sigbit(m)); printf ("\nTesting: b2n_sqrt: "); diff --git a/sbin/isakmpd/regress/ec2n/ec2ntest.c b/sbin/isakmpd/regress/ec2n/ec2ntest.c index 58cbbc3808d..ff4f0e9efc9 100644 --- a/sbin/isakmpd/regress/ec2n/ec2ntest.c +++ b/sbin/isakmpd/regress/ec2n/ec2ntest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec2ntest.c,v 1.3 1998/12/21 01:02:30 niklas Exp $ */ +/* $OpenBSD: ec2ntest.c,v 1.4 2002/01/23 17:43:24 ho Exp $ */ /* $EOM: ec2ntest.c,v 1.3 1998/07/16 09:21:59 niklas Exp $ */ /* @@ -47,7 +47,9 @@ #include "math_2n.h" #include "math_ec2n.h" -#define CMP_FAIL(n,x) b2n_sprint (buf, n); if (strcmp (buf, (x))) \ +#define BUFSIZE 200 + +#define CMP_FAIL(n,x) b2n_snprint (buf, BUFSIZE, n); if (strcmp (buf, (x))) \ printf ("FAILED: %s != %s ", buf, x); else printf ("OKAY "); int @@ -56,7 +58,7 @@ main (void) b2n_t k; ec2np_t p, q, r; ec2ng_t g; - char buf[200]; + char buf[BUFSIZE]; b2n_init (k); ec2np_init (p); |