[HQ-93] un-clobber stack data in sigar_gethostbyname
This commit is contained in:
parent
f1a13a3361
commit
5c26b463d9
|
@ -239,4 +239,23 @@ int sigar_get_iftype(const char *name, int *type, int *inst);
|
||||||
#define SIGAR_NIC_ETHERNET "Ethernet"
|
#define SIGAR_NIC_ETHERNET "Ethernet"
|
||||||
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SIGAR_GETHOSTBYNAME_LEN 512
|
||||||
|
#if defined(__hpux) || defined(_AIX)
|
||||||
|
#define SIGAR_HAS_HOSTENT_DATA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char buffer[SIGAR_GETHOSTBYNAME_LEN];
|
||||||
|
struct hostent hs;
|
||||||
|
int error;
|
||||||
|
#ifdef SIGAR_HAS_HOSTENT_DATA
|
||||||
|
struct hostent_data hd;
|
||||||
|
#endif
|
||||||
|
} sigar_hostent_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
|
|
||||||
char *sigar_uitoa(char *buf, unsigned int n, int *len);
|
char *sigar_uitoa(char *buf, unsigned int n, int *len);
|
||||||
|
|
||||||
struct hostent *sigar_gethostbyname(const char *name);
|
struct hostent *sigar_gethostbyname(const char *name,
|
||||||
|
sigar_hostent_t *data);
|
||||||
|
|
||||||
SIGAR_INLINE char *sigar_skip_line(char *buffer, int buflen);
|
SIGAR_INLINE char *sigar_skip_line(char *buffer, int buflen);
|
||||||
|
|
||||||
|
|
43
src/sigar.c
43
src/sigar.c
|
@ -1547,34 +1547,26 @@ static int fqdn_ip_get(sigar_t *sigar, char *name)
|
||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
struct hostent *sigar_gethostbyname(const char *name,
|
||||||
#else
|
sigar_hostent_t *data)
|
||||||
#include <netdb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GETHOSTBYNAME_LEN 512
|
|
||||||
#if defined(__hpux) || defined(_AIX)
|
|
||||||
#define HAS_HOSTENT_DATA
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct hostent *sigar_gethostbyname(const char *name)
|
|
||||||
{
|
{
|
||||||
char buffer[GETHOSTBYNAME_LEN];
|
struct hostent *hp = NULL;
|
||||||
struct hostent hs, *hp;
|
|
||||||
int err;
|
|
||||||
#if defined(HAS_HOSTENT_DATA)
|
|
||||||
struct hostent_data hd;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
gethostbyname_r(name, &hs, buffer, sizeof(buffer),
|
gethostbyname_r(name, &data->hs,
|
||||||
&hp, &err);
|
data->buffer, sizeof(data->buffer),
|
||||||
|
&hp, &data->error);
|
||||||
#elif defined(__sun)
|
#elif defined(__sun)
|
||||||
hp = gethostbyname_r(name, &hs, buffer, sizeof(buffer),
|
hp = gethostbyname_r(name, &data->hs,
|
||||||
&err);
|
data->buffer, sizeof(data->buffer),
|
||||||
#elif defined(HAS_HOSTENT_DATA)
|
&data->error);
|
||||||
gethostbyname_r(name, &hs, &hd);
|
#elif defined(SIGAR_HAS_HOSTENT_DATA)
|
||||||
hp = &hs;
|
if (gethostbyname_r(name, &data->hs, &data->hd) == 0) {
|
||||||
|
hp = &data->hs;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data->error = h_errno;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
hp = gethostbyname(name);
|
hp = gethostbyname(name);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1593,6 +1585,7 @@ struct hostent *sigar_gethostbyname(const char *name)
|
||||||
|
|
||||||
SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen)
|
SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen)
|
||||||
{
|
{
|
||||||
|
sigar_hostent_t data;
|
||||||
struct hostent *p;
|
struct hostent *p;
|
||||||
char domain[SIGAR_FQDN_LEN + 1];
|
char domain[SIGAR_FQDN_LEN + 1];
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -1618,7 +1611,7 @@ SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX use _r versions of these functions. */
|
/* XXX use _r versions of these functions. */
|
||||||
if (!(p = sigar_gethostbyname(name))) {
|
if (!(p = sigar_gethostbyname(name, &data))) {
|
||||||
if (SIGAR_LOG_IS_DEBUG(sigar)) {
|
if (SIGAR_LOG_IS_DEBUG(sigar)) {
|
||||||
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
|
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
|
||||||
"[fqdn] gethostbyname(%s) failed: %s",
|
"[fqdn] gethostbyname(%s) failed: %s",
|
||||||
|
|
|
@ -496,12 +496,13 @@ int sigar_cpu_mhz_from_model(char *model)
|
||||||
static enum clnt_stat get_sockaddr(struct sockaddr_in *addr, char *host)
|
static enum clnt_stat get_sockaddr(struct sockaddr_in *addr, char *host)
|
||||||
{
|
{
|
||||||
register struct hostent *hp;
|
register struct hostent *hp;
|
||||||
|
sigar_hostent_t data;
|
||||||
|
|
||||||
memset(addr, 0, sizeof(struct sockaddr_in));
|
memset(addr, 0, sizeof(struct sockaddr_in));
|
||||||
addr->sin_family = AF_INET;
|
addr->sin_family = AF_INET;
|
||||||
|
|
||||||
if ((addr->sin_addr.s_addr = inet_addr(host)) == -1) {
|
if ((addr->sin_addr.s_addr = inet_addr(host)) == -1) {
|
||||||
if (!(hp = sigar_gethostbyname(host))) {
|
if (!(hp = sigar_gethostbyname(host, &data))) {
|
||||||
return RPC_UNKNOWNHOST;
|
return RPC_UNKNOWNHOST;
|
||||||
}
|
}
|
||||||
memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
|
memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
|
||||||
|
|
Loading…
Reference in New Issue