This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch:] iconv/gconv.c: Don't refer to parameter cd before testing for validity.


Hi.  While working on a glibc port to Linux/CRIS (cris-axis-linux-gnu),
I've stumbled on a few glibc bugs, some by visual inspection and some by
executing code.  I'm sending everything as separate patches.

If parameter cd can be (__gconv_t) -1L, then I guess it shouldn't be
accessed before checked.

2001-04-08  Hans-Peter Nilsson  <hp@axis.com>

	* iconv/gconv.c (__gconv): Don't derefer parameter cd before
	checking if == -1L.

Index: gconv.c
===================================================================
RCS file: /cvs/glibc/libc/iconv/gconv.c,v
retrieving revision 1.23
diff -p -c -r1.23 gconv.c
*** gconv.c	2000/11/20 08:48:18	1.23
--- gconv.c	2001/04/08 21:37:37
***************
*** 1,6 ****
  /* Convert characters in input buffer using conversion descriptor to
     output buffer.
!    Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
     This file is part of the GNU C Library.
     Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  
--- 1,6 ----
  /* Convert characters in input buffer using conversion descriptor to
     output buffer.
!    Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
     This file is part of the GNU C Library.
     Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  
*************** __gconv (__gconv_t cd, const unsigned ch
*** 31,41 ****
  	 const unsigned char *inbufend, unsigned char **outbuf,
  	 unsigned char *outbufend, size_t *irreversible)
  {
!   size_t last_step = cd->__nsteps - 1;
    int result;
  
    if (cd == (__gconv_t) -1L)
      return __GCONV_ILLEGAL_DESCRIPTOR;
  
    assert (irreversible != NULL);
    *irreversible = 0;
--- 31,43 ----
  	 const unsigned char *inbufend, unsigned char **outbuf,
  	 unsigned char *outbufend, size_t *irreversible)
  {
!   size_t last_step;
    int result;
  
    if (cd == (__gconv_t) -1L)
      return __GCONV_ILLEGAL_DESCRIPTOR;
+ 
+   last_step = cd->__nsteps - 1;
  
    assert (irreversible != NULL);
    *irreversible = 0;

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]