Mercurial > illumos > illumos-gate
changeset 14085:c1602d3adc9b
1986 libima misuses gethostname
Reviewed by: David Höppner <0xffea@gmail.com>
Reviewed by: Andy Stormont <andyjstormont@gmail.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
author | Matt Barden <matt.barden@nexenta.com> |
---|---|
date | Tue, 23 Jul 2013 13:45:45 -0400 |
parents | 9919574e3322 |
children | cc3db4d15c60 |
files | usr/src/lib/libima/Makefile.com usr/src/lib/libima/common/ima-lib.c |
diffstat | 2 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/lib/libima/Makefile.com Thu Jul 18 22:44:14 2013 -0400 +++ b/usr/src/lib/libima/Makefile.com Tue Jul 23 13:45:45 2013 -0400 @@ -51,7 +51,6 @@ CFLAGS64 += -DSOLARIS CERRWARN += -_gcc=-Wno-unused-variable -CERRWARN += -_gcc=-Wno-implicit-function-declaration LINTFLAGS += -DSOLARIS LINTFLAGS64 += -DSOLARIS
--- a/usr/src/lib/libima/common/ima-lib.c Thu Jul 18 22:44:14 2013 -0400 +++ b/usr/src/lib/libima/common/ima-lib.c Tue Jul 23 13:45:45 2013 -0400 @@ -36,20 +36,21 @@ #ifdef WIN32 #include <windows.h> #else -#define _XOPEN_SOURCE /* glibc2 needs this */ #include <sys/sem.h> #include <dlfcn.h> #include <stdarg.h> #endif #include <string.h> +#include <strings.h> #include <stdlib.h> // #include <sys/sem.h> -// #include <unistd.h> +#include <unistd.h> #include <time.h> #include <stdio.h> #include <sys/types.h> // #include <sys/ipc.h> +#include <netdb.h> #include "libsun_ima.h" #include "ima.h" @@ -277,11 +278,11 @@ * "__attribute__ ((constructor))" and "__attribute__ ((destructor))" * are used with gcc */ -__attribute__ ((constructor)) void init() { +__attribute__((constructor)) void init() { InitLibrary(); } -__attribute__ ((destructor)) void fini() { +__attribute__((destructor)) void fini() { ExitLibrary(); } @@ -1021,8 +1022,11 @@ IMA_UINT i; IMA_STATUS status; char fullline[512]; /* Full line read in from IMA.conf */ - char nodename[256]; + char nodename[MAXHOSTNAMELEN]; + +#if defined(_WINDOWS) IMA_UINT dwStrLength; +#endif if (number_of_plugins == -1) InitLibrary(); @@ -1050,13 +1054,14 @@ if (getSolarisSharedNodeName(sharedNodeName) != IMA_STATUS_SUCCESS) { - gethostname((char *)fullline, &dwStrLength); + gethostname((char *)fullline, + sizeof (fullline)); sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, fullline); mbstowcs(sharedNodeName, nodename, 256); } #else - gethostname((char *)fullline, &dwStrLength); + gethostname((char *)fullline, sizeof (fullline)); sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, fullline); mbstowcs(sharedNodeName, nodename, 256); #endif @@ -1222,16 +1227,18 @@ IMA_API IMA_STATUS IMA_GenerateNodeName( IMA_NODE_NAME generatedname) { char computername[256]; - char nodename[256]; - IMA_UINT dwStrLength; + char nodename[MAXHOSTNAMELEN]; + +#if defined(_WINDOWS) + IMA_UINT dwStrLength = 255; +#endif + #ifndef _WINDOWS #ifndef SOLARIS int i; #endif #endif - dwStrLength = 255; - if (generatedname == NULL) return (IMA_ERROR_INVALID_PARAMETER); @@ -1243,12 +1250,12 @@ generatedname, 256); #elif defined(SOLARIS) if (getSolarisSharedNodeName(generatedname) != IMA_STATUS_SUCCESS) { - gethostname(computername, &dwStrLength); + gethostname(computername, sizeof (computername)); sprintf(nodename, DEFAULT_NODE_NAME_FORMAT, generatedname); mbstowcs(generatedname, nodename, 256); } #else - gethostname((char *)computername, &dwStrLength); + gethostname((char *)computername, sizeof (computername)); i = 0; while (computername[i] != '\0') { computername[i] = tolower(computername[i]);