| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>, Martin Renters <martin(at)datafax(dot)com> | 
| Cc: | Philip Warner <pjw(at)rhyme(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: beta6 pg_restore core dumps | 
| Date: | 2001-03-17 17:31:20 | 
| Message-ID: | 1449.984850280@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
After looking more closely I see that pg_restore has two different
buffer overrun conditions in this one routine.  Attached is take two
of my patch.
This would be a lot simpler and cleaner if _PrintData() simply didn't
append a zero byte to the buffer contents.  Philip, is it actually
necessary for it to do that?
regards, tom lane
*** pg_backup_custom.c.orig	Fri Feb  9 17:32:26 2001
--- pg_backup_custom.c	Sat Mar 17 12:25:17 2001
***************
*** 150,156 ****
      if (ctx->zp == NULL)
  	die_horribly(AH, "%s: unable to allocate zlib stream archive context",progname);
  
!     ctx->zlibOut = (char*)malloc(zlibOutSize);
      ctx->zlibIn = (char*)malloc(zlibInSize);
      ctx->inSize = zlibInSize;
      ctx->filePos = 0;
--- 150,163 ----
      if (ctx->zp == NULL)
  	die_horribly(AH, "%s: unable to allocate zlib stream archive context",progname);
  
! 	/*
! 	 * zlibOutSize is the buffer size we tell zlib it can output to.  We
! 	 * actually allocate one extra byte because some routines want to append
! 	 * a trailing zero byte to the zlib output.  The input buffer is expansible
! 	 * and is always of size ctx->inSize; zlibInSize is just the initial
! 	 * default size for it.
! 	 */
!     ctx->zlibOut = (char*)malloc(zlibOutSize+1);
      ctx->zlibIn = (char*)malloc(zlibInSize);
      ctx->inSize = zlibInSize;
      ctx->filePos = 0;
***************
*** 518,531 ****
  
      blkLen = ReadInt(AH);
      while (blkLen != 0) {
! 		if (blkLen > (ctx->inSize - 1)) {
  			free(ctx->zlibIn);
  			ctx->zlibIn = NULL;
! 			ctx->zlibIn = (char*)malloc(blkLen);
  			if (!ctx->zlibIn)
  				die_horribly(AH, "%s: failed to allocate decompression buffer\n", progname);
  
! 			ctx->inSize = blkLen;
  			in = ctx->zlibIn;
  		}
  
--- 525,538 ----
  
      blkLen = ReadInt(AH);
      while (blkLen != 0) {
! 		if (blkLen+1 > ctx->inSize) {
  			free(ctx->zlibIn);
  			ctx->zlibIn = NULL;
! 			ctx->zlibIn = (char*)malloc(blkLen+1);
  			if (!ctx->zlibIn)
  				die_horribly(AH, "%s: failed to allocate decompression buffer\n", progname);
  
! 			ctx->inSize = blkLen+1;
  			in = ctx->zlibIn;
  		}
  
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2001-03-17 17:38:36 | Re: Performance monitor signal handler | 
| Previous Message | Bruce Momjian | 2001-03-17 17:10:37 | Re: Performance monitor signal handler |