Re: oaf gethostby* bug
- From: Maciej Stachowiak <mjs eazel com>
- To: Dan Winship <danw helixcode com>
- Cc: gnome-components-list gnome org
- Subject: Re: oaf gethostby* bug
- Date: 13 Sep 2000 16:47:15 -0700
Dan Winship <danw helixcode com> writes:
> oaf_hostname_get assumes it can pass the result of gethostbyname as an
> argument to gethostbyaddr, which is not safe, since they might be
> using the same static buffer. Mmmm... static data.
Silly libc, static buffers are for kids. Please check in (with
appropriate ChangeLog entry).
- Maciej
> Index: liboaf/oaf-mainloop.c
> ===================================================================
> RCS file: /cvs/gnome/oaf/liboaf/oaf-mainloop.c,v
> retrieving revision 1.23
> diff -u -r1.23 oaf-mainloop.c
> --- liboaf/oaf-mainloop.c 2000/08/11 23:15:57 1.23
> +++ liboaf/oaf-mainloop.c 2000/09/13 19:51:33
> @@ -119,23 +119,24 @@
> oaf_hostname_get (void)
> {
> static char *hostname = NULL;
> - char hn_tmp[65];
> - struct hostent *hent, *hent2;
> + char hn_tmp[65], ha_tmp[4];
> + struct hostent *hent;
>
> if (!hostname) {
> gethostname (hn_tmp, sizeof (hn_tmp) - 1);
>
> hent = gethostbyname (hn_tmp);
> if (hent) {
> - hent2 = gethostbyaddr (hent->h_addr, 4, AF_INET);
> - if (hent2)
> - hostname = g_strdup (hent2->h_name);
> + memcpy (ha_tmp, hent->h_addr, 4);
> + hent = gethostbyaddr (ha_tmp, 4, AF_INET);
> + if (hent)
> + hostname = g_strdup (hent->h_name);
> else
> hostname =
> g_strdup (inet_ntoa
> (*
> ((struct in_addr *)
> - hent->h_addr)));
> + ha_tmp)));
> } else
> hostname = g_strdup (hn_tmp);
> }
>
> _______________________________________________
> gnome-components-list mailing list
> gnome-components-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-components-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]