sysctl(3) can return an error (setting errno to ENOMEM) when the
fields in the utsname structure are too small to hold their corresponding MIB variables. Don't return an error in this case.
This commit is contained in:
parent
5411ea9d8c
commit
b938dc2407
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=3565
@ -32,12 +32,15 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94";
|
||||
/*static char sccsid[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
uname(name)
|
||||
@ -46,45 +49,73 @@ uname(name)
|
||||
int mib[2], rval;
|
||||
size_t len;
|
||||
char *p;
|
||||
int oerrno;
|
||||
|
||||
rval = 0;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSTYPE;
|
||||
len = sizeof(name->sysname);
|
||||
if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_HOSTNAME;
|
||||
len = sizeof(name->nodename);
|
||||
if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSRELEASE;
|
||||
len = sizeof(name->release);
|
||||
if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
/* The version may have newlines in it, turn them into spaces. */
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_VERSION;
|
||||
len = sizeof(name->version);
|
||||
if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
else
|
||||
for (p = name->version; len--; ++p)
|
||||
if (*p == '\n' || *p == '\t')
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
} else {
|
||||
for (p = name->version; len--; ++p) {
|
||||
if (*p == '\n' || *p == '\t') {
|
||||
if (len > 1)
|
||||
*p = ' ';
|
||||
else
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MACHINE;
|
||||
len = sizeof(name->machine);
|
||||
if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
return (rval);
|
||||
}
|
||||
|
@ -32,12 +32,15 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94";
|
||||
/*static char sccsid[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
uname(name)
|
||||
@ -46,45 +49,73 @@ uname(name)
|
||||
int mib[2], rval;
|
||||
size_t len;
|
||||
char *p;
|
||||
int oerrno;
|
||||
|
||||
rval = 0;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSTYPE;
|
||||
len = sizeof(name->sysname);
|
||||
if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_HOSTNAME;
|
||||
len = sizeof(name->nodename);
|
||||
if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSRELEASE;
|
||||
len = sizeof(name->release);
|
||||
if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) {
|
||||
if(errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
/* The version may have newlines in it, turn them into spaces. */
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_VERSION;
|
||||
len = sizeof(name->version);
|
||||
if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
else
|
||||
for (p = name->version; len--; ++p)
|
||||
if (*p == '\n' || *p == '\t')
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
} else {
|
||||
for (p = name->version; len--; ++p) {
|
||||
if (*p == '\n' || *p == '\t') {
|
||||
if (len > 1)
|
||||
*p = ' ';
|
||||
else
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MACHINE;
|
||||
len = sizeof(name->machine);
|
||||
if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1)
|
||||
rval = -1;
|
||||
oerrno = errno;
|
||||
if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM)
|
||||
errno = oerrno;
|
||||
else
|
||||
rval = -1;
|
||||
}
|
||||
return (rval);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user