diff options
author | mpp <mpp@FreeBSD.org> | 1995-07-31 10:10:02 +0000 |
---|---|---|
committer | mpp <mpp@FreeBSD.org> | 1995-07-31 10:10:02 +0000 |
commit | 51c2dd9b11cdf65018cc3049867cdcb385485d65 (patch) | |
tree | 7ce275cea9847f4f0aa09f87a895c33da2f5804d /lib/libc/gen/uname.c | |
parent | 08d1bb1b892e340765b0d6e348481660b3d28481 (diff) | |
download | FreeBSD-src-51c2dd9b11cdf65018cc3049867cdcb385485d65.zip FreeBSD-src-51c2dd9b11cdf65018cc3049867cdcb385485d65.tar.gz |
Null terminate all strings returned by the dummy uname() routine,
and make sure that the version string is somewhat sane. This
closes out PR#462.
Reviewed by: Bruce Evans
Diffstat (limited to 'lib/libc/gen/uname.c')
-rw-r--r-- | lib/libc/gen/uname.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c index 63f2956..93f659e 100644 --- a/lib/libc/gen/uname.c +++ b/lib/libc/gen/uname.c @@ -34,7 +34,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char sccsid[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/ static const char rcsid[] = - "$Id: uname.c,v 1.2 1994/10/13 20:31:19 wollman Exp $"; + "$Id: uname.c,v 1.3 1995/05/30 05:40:29 rgrimes Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -63,6 +63,7 @@ uname(name) else rval = -1; } + name->sysname[sizeof(name->sysname) - 1] = '\0'; mib[0] = CTL_KERN; mib[1] = KERN_HOSTNAME; @@ -74,6 +75,7 @@ uname(name) else rval = -1; } + name->nodename[sizeof(name->nodename) - 1] = '\0'; mib[0] = CTL_KERN; mib[1] = KERN_OSRELEASE; @@ -85,6 +87,7 @@ uname(name) else rval = -1; } + name->release[sizeof(name->release) - 1] = '\0'; /* The version may have newlines in it, turn them into spaces. */ mib[0] = CTL_KERN; @@ -96,14 +99,14 @@ uname(name) errno = oerrno; else rval = -1; - } else { - for (p = name->version; len--; ++p) { - if (*p == '\n' || *p == '\t') { - if (len > 1) - *p = ' '; - else - *p = '\0'; - } + } + name->version[sizeof(name->version) - 1] = '\0'; + for (p = name->version; len--; ++p) { + if (*p == '\n' || *p == '\t') { + if (len > 1) + *p = ' '; + else + *p = '\0'; } } @@ -117,5 +120,6 @@ uname(name) else rval = -1; } + name->machine[sizeof(name->machine) - 1] = '\0'; return (rval); } |