glibc i zwisy poldka
Jakub Bogusz
qboosh w pld-linux.org
Pią, 8 Kwi 2005, 16:45:57 CEST
On Fri, Apr 08, 2005 at 03:12:19PM +0200, Arkadiusz Miskiewicz wrote:
> W załączniku prosty testcase,
>
> na 2.3.5 daje:
> zfseek (0x8049aa0, 0, 0, 1) = 0
> 1: 0
> zfseek (0x8049aa0, 0, 0, 1) = 0
> 2: / -1
> (ftell zwraca -1)
>
> na 2.3.4
> zfseek (0x96e0050, 0, 0, 1) = 0
> 1: 0
> 2: / 1
> (ftell zwraca prawdę)
>
> Test przez:
> gcc testcookie.c -lz -Wall; ./a.out jakis.gzipniety.plik.gz
>
> poldek zwisa dlatego, że dostaje od ftell -1 zamiast czegoś sensownego w
> jednym miejscu i się zapętla na amen (nie ma sprawdzania co ftell zwróciło).
Pewnie chodzi zmiany w libio/iofopncook.c (pomijam dodane testy, do
znalezienia w źródłach lub CVS).
2005-01-19 Jakub Jelinek <jakub w redhat.com>
[BZ #730]
* libio/iofopncook.c (_IO_cookie_seekoff): Add prototype.
2005-01-05 Ulrich Drepper <drepper w redhat.com>
[BZ #730]
* libio/iofopncook.c (_IO_cookie_seekoff): Define. Mark offset as
invalid to disable optimizations in fileops which won't work here.
(_IO_cookie_jumps): Use it.
(_IO_old_cookie_jumps): Likewise.
* libio/fmemopen.c (fmemopen_seek): Result must be returned in *P,
not the return value.
* stdio-common/Makefile (tests): Add tst-fmemopen2.
* stdio-common/tst-fmemopen2.c: New file.
diff -Nurp glibc-2.3.4/libio/fmemopen.c glibc-2.3.5/libio/fmemopen.c
--- glibc-2.3.4/libio/fmemopen.c 2002-08-25 04:47:57.000000000 +0200
+++ glibc-2.3.5/libio/fmemopen.c 2005-03-01 21:57:17.000000000 +0100
@@ -1,5 +1,5 @@
/* Fmemopen implementation.
- Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Hanno Mueller, kontakt w hanno.de, 2000.
@@ -27,8 +27,6 @@
* but couldn't find it in libio. The following snippet of code is an
* attempt to implement what glibc's documentation describes.
*
- * No, it isn't really tested yet. :-)
- *
*
*
* I already see some potential problems:
@@ -73,6 +71,7 @@
#include <libio.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include "libioP.h"
@@ -166,7 +165,7 @@ fmemopen_seek (void *cookie, _IO_off64_t
break;
case SEEK_END:
- np = c->size - *p;
+ np = c->maxpos - *p;
break;
default:
@@ -176,9 +175,9 @@ fmemopen_seek (void *cookie, _IO_off64_t
if (np < 0 || (size_t) np > c->size)
return -1;
- c->pos = np;
+ *p = c->pos = np;
- return np;
+ return 0;
}
@@ -203,6 +202,13 @@ fmemopen (void *buf, size_t len, const c
cookie_io_functions_t iof;
fmemopen_cookie_t *c;
+ if (len == 0)
+ {
+ einval:
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t));
if (c == NULL)
return NULL;
@@ -220,7 +226,12 @@ fmemopen (void *buf, size_t len, const c
c->buffer[0] = '\0';
}
else
- c->buffer = buf;
+ {
+ if ((uintptr_t) len > -(uintptr_t) buf)
+ goto einval;
+
+ c->buffer = buf;
+ }
c->size = len;
diff -Nurp glibc-2.3.4/libio/iofopncook.c glibc-2.3.5/libio/iofopncook.c
--- glibc-2.3.4/libio/iofopncook.c 2004-03-10 10:28:25.000000000 +0100
+++ glibc-2.3.5/libio/iofopncook.c 2005-02-16 10:45:20.000000000 +0100
@@ -36,6 +36,8 @@ static _IO_ssize_t _IO_cookie_read (regi
static _IO_ssize_t _IO_cookie_write (register _IO_FILE* fp,
const void* buf, _IO_ssize_t size);
static _IO_off64_t _IO_cookie_seek (_IO_FILE *fp, _IO_off64_t offset, int dir);
+static _IO_off64_t _IO_cookie_seekoff (_IO_FILE *fp, _IO_off64_t offset,
+ int dir, int mode);
static int _IO_cookie_close (_IO_FILE* fp);
static _IO_ssize_t
@@ -94,6 +96,20 @@ _IO_cookie_close (fp)
}
+static _IO_off64_t
+_IO_cookie_seekoff (fp, offset, dir, mode)
+ _IO_FILE *fp;
+ _IO_off64_t offset;
+ int dir;
+ int mode;
+{
+ /* We must force the fileops code to always use seek to determine
+ the position. */
+ fp->_offset = _IO_pos_BAD;
+ return INTUSE(_IO_file_seekoff) (fp, offset, dir, mode);
+}
+
+
static const struct _IO_jump_t _IO_cookie_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, INTUSE(_IO_file_finish)),
@@ -103,7 +119,7 @@ static const struct _IO_jump_t _IO_cooki
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
- JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)),
+ JUMP_INIT(seekoff, _IO_cookie_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)),
JUMP_INIT(sync, INTUSE(_IO_file_sync)),
@@ -223,7 +239,7 @@ static const struct _IO_jump_t _IO_old_c
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
- JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)),
+ JUMP_INIT(seekoff, _IO_cookie_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)),
JUMP_INIT(sync, INTUSE(_IO_file_sync)),
--
Jakub Bogusz http://cyber.cs.net.pl/~qboosh/
Więcej informacji o liście dyskusyjnej pld-devel-pl