bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile segfault with network calls


From: Dirk Herrmann
Subject: Re: Guile segfault with network calls
Date: Sat, 3 Mar 2001 14:50:18 +0100 (MET)

On 3 Mar 2001, Gary Houston wrote:

> If it was implemented like that, sizeof wouldn't work.  How about this:
> 
> --- socket.c    2001/02/02 04:56:25     1.60
> +++ socket.c    2001/03/03 13:19:32
> @@ -425,15 +425,21 @@
>      case AF_UNIX:
>        {
>         struct sockaddr_un *soka;
> +       size_t addr_size;
>  
> +       SCM_ASSERT (SCM_STRINGP (address), address, which_arg, proc);
> +       /* the static buffer size in sockaddr_un seems to be arbitrary
> +          and not necessarily a hard limit.  let's ignore it.
> +          sun_path is always the last member of the structure.  */
> +       addr_size = sizeof (struct sockaddr_un)
> +         + max (0, SCM_STRING_LENGTH (address) + 1 - (sizeof 
> soka->sun_path));
>         soka = (struct sockaddr_un *)
> -         scm_must_malloc (sizeof (struct sockaddr_un), proc);
> -       memset (soka, 0, sizeof (struct sockaddr_un));
> +         scm_must_malloc (addr_size, proc);
> +       memset (soka, 0, addr_size);  /* for sun_len: see sin_len above. */
>         soka->sun_family = AF_UNIX;
> -       SCM_ASSERT (SCM_STRINGP (address), address, which_arg, proc);
>         memcpy (soka->sun_path, SCM_STRING_CHARS (address),
> -               1 + SCM_STRING_LENGTH (address));
> -       *size = sizeof (struct sockaddr_un);
> +               SCM_STRING_LENGTH (address) + 1);

                                              ^^^  Is this necessary?
(It will only copy a null byte, which is already created by memset.)

> +       *size = SUN_LEN (soka);
>         return (struct sockaddr *) soka;
>        }
>  #endif

Nice trick.  (Please note my comment above.)

Best regards,
Dirk Herrmann




reply via email to

[Prev in Thread] Current Thread [Next in Thread]