From 982e80577dd08945aa2345ebe35e3f50eef9eb48 Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 4 Dec 1998 22:54:57 +0000 Subject: Examine all occurrences of sprintf(), strcat(), and str[n]cpy() for possible buffer overflow problems. Replaced most sprintf()'s with snprintf(); for others cases, added terminating NUL bytes where appropriate, replaced constants like "16" with sizeof(), etc. These changes include several bug fixes, but most changes are for maintainability's sake. Any instance where it wasn't "immediately obvious" that a buffer overflow could not occur was made safer. Reviewed by: Bruce Evans Reviewed by: Matthew Dillon Reviewed by: Mike Spengler --- sys/i386/linux/linux_misc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'sys/i386/linux/linux_misc.c') diff --git a/sys/i386/linux/linux_misc.c b/sys/i386/linux/linux_misc.c index 9fdd923..35ce1bf 100644 --- a/sys/i386/linux/linux_misc.c +++ b/sys/i386/linux/linux_misc.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: linux_misc.c,v 1.44 1998/09/24 13:25:43 jkh Exp $ + * $Id: linux_misc.c,v 1.45 1998/10/05 12:40:42 sos Exp $ */ #include @@ -746,12 +746,18 @@ linux_newuname(struct proc *p, struct linux_newuname_args *args) printf("Linux-emul(%d): newuname(*)\n", p->p_pid); #endif bzero(&linux_newuname, sizeof(struct linux_newuname_t)); - strncpy(linux_newuname.sysname, ostype, 64); - strncpy(linux_newuname.nodename, hostname, 64); - strncpy(linux_newuname.release, osrelease, 64); - strncpy(linux_newuname.version, version, 64); - strncpy(linux_newuname.machine, machine, 64); - strncpy(linux_newuname.domainname, domainname, 64); + strncpy(linux_newuname.sysname, ostype, + sizeof(linux_newuname.sysname) - 1); + strncpy(linux_newuname.nodename, hostname, + sizeof(linux_newuname.nodename) - 1); + strncpy(linux_newuname.release, osrelease, + sizeof(linux_newuname.release) - 1); + strncpy(linux_newuname.version, version, + sizeof(linux_newuname.version) - 1); + strncpy(linux_newuname.machine, machine, + sizeof(linux_newuname.machine) - 1); + strncpy(linux_newuname.domainname, domainname, + sizeof(linux_newuname.domainname) - 1); return (copyout((caddr_t)&linux_newuname, (caddr_t)args->buf, sizeof(struct linux_newuname_t))); } -- cgit v1.1