On Fri, Oct 14, 2011 at 09:40:42AM -0400, Todd C. Miller wrote:

> The (existing) abuse of toprec is a bit kludgy but this should fix
> the problem for now.

yes it does, also tested termcap and termlib db creation. But you are
right, the code is a bit ugly,

        -Otto

> 
>  - todd
> 
> Index: lib/libc/gen/getcap.c
> ===================================================================
> RCS file: /home/cvs/openbsd/src/lib/libc/gen/getcap.c,v
> retrieving revision 1.29
> diff -u -r1.29 getcap.c
> --- lib/libc/gen/getcap.c     10 Jul 2011 13:31:02 -0000      1.29
> +++ lib/libc/gen/getcap.c     14 Oct 2011 13:30:07 -0000
> @@ -658,11 +658,12 @@
>  int
>  cgetnext(char **cap, char **db_array)
>  {
> -     size_t len;
> +     size_t len, otopreclen = topreclen;
>       int c, serrno, status = -1;
>       char buf[BUFSIZ], nbuf[BSIZE];
>       char *b_end, *bp, *r_end, *rp;
>       char *record = NULL;
> +     char *otoprec = toprec;
>       u_int dummy;
>       off_t pos;
>  
> @@ -677,6 +678,7 @@
>        */
>       if (toprec && !gottoprec) {
>               gottoprec = 1;
> +             record = toprec;
>               goto lookup;
>       }
>  
> @@ -770,7 +772,6 @@
>                       fseeko(pfp, (off_t)(bp - b_end), SEEK_CUR);
>                       toprec = record;
>                       topreclen = rp - record;
> -                     gottoprec = 1;
>                       break;
>               }
>       }
> @@ -787,7 +788,11 @@
>               fseeko(pfp, pos, SEEK_SET);
>  done:
>       serrno = errno;
> -     free(record);
> +     if (toprec != otoprec) {
> +             toprec = otoprec;
> +             topreclen = otopreclen;
> +             free(record);
> +     }
>       if (status <= 0)
>               (void)cgetclose();
>       errno = serrno;

Reply via email to