snprintf patches

"Dunceor ." <[email protected]> Fri, 18 Mar 2005 13:12:57 +0100
Newsgroups gmane.comp.security.libnet
Message-ID <[email protected]>
------=_Part_1563_21026621.1111147977690
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hey all.
I just upgraded my old sparc box to OpenBSD 3.7-current and then (of
course) installed libnet from source (1.1.2.1).
OpenBSD have done some adds to gcc so that gcc warns you when sprint
is being used (just as they have done with strcpy, strcat and strcmp
before).
I then saw there is a few sprintf's in the code and I'd thought I'd patch them.
They arn't in anyway a security risk, I just think it's good
programming to use snprintf and Mike has used snprintf also but some
old sprintf's left.

Well a few patches there, feel free to use.

Thanks.

// Dunceor

------=_Part_1563_21026621.1111147977690
Content-Type: text/plain; name="libnet_build_gre.c.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="libnet_build_gre.c.patch"

--- libnet_build_gre.c=09Sun Feb 22 20:45:06 2004
+++ libnet_build_gre.c=09Fri Mar 18 12:46:28 2005
@@ -255,7 +255,7 @@
=20
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20
@@ -345,7 +345,7 @@
=20
     if ((routing && !length) || (!routing && length))
     {
-        sprintf(l->err_buf, "%s(): routing inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): routing inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20
@@ -361,7 +361,7 @@
=20
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20

------=_Part_1563_21026621.1111147977690
Content-Type: text/plain; name="libnet_build_ip.c.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="libnet_build_ip.c.patch"

--- libnet_build_ip.c=09Tue Mar 16 19:40:59 2004
+++ libnet_build_ip.c=09Fri Mar 18 12:37:57 2005
@@ -583,7 +583,7 @@
      */
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf,LIBNET_ERRBUF_SIZE , "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20
@@ -670,7 +670,7 @@
      */
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20
@@ -754,7 +754,7 @@
      */
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20
@@ -838,7 +838,7 @@
      */
     if ((payload && !payload_s) || (!payload && payload_s))
     {
-        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): payload inconsiste=
ncy\n", __func__);
         goto bad;
     }
=20

------=_Part_1563_21026621.1111147977690
Content-Type: text/plain; name="libnet_link_bpf.c.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="libnet_link_bpf.c.patch"

--- libnet_link_bpf.c=09Wed Jan 28 20:45:00 2004
+++ libnet_link_bpf.c=09Fri Mar 18 11:35:51 2005
@@ -61,7 +61,7 @@
      */
     for (i =3D 0;;i++)
     {
-        sprintf(device, "/dev/bpf%d", i);
+        snprintf(device, sizeof "/dev/bpf000", "/dev/bpf%d", i);
=20
         fd =3D open(device, O_RDWR);
         if (fd =3D=3D -1 && errno =3D=3D EBUSY)

------=_Part_1563_21026621.1111147977690--