[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Libcdio-devel] [PATCH] Non LFS dependent fseeko detection and off_t
From: |
Rocky Bernstein |
Subject: |
Re: [Libcdio-devel] [PATCH] Non LFS dependent fseeko detection and off_t truncation checks |
Date: |
Tue, 24 Jan 2012 22:53:05 -0500 |
On Tue, Jan 24, 2012 at 8:14 PM, Pete Batard <address@hidden> wrote:
> Last commit of mine from -pbatard (= attached patch) fixes the issue
> previous observed on ARM and cygwin by:
>
> - adding fseeko detection that doesn't rely on LFS
> - detecting truncation of off_t when LFS is in use but fseeko was not
> detected.
>
While all of this is good, the two thoughts.
First figuring out what is wrong with HAVE_FSEEKO so that can be reported
back to the autoconf folks. (That said, I haven't had much luck in getting
changes back).
Second, as alluded to previously, should there be a --enable/--disable
configure switch to try to force one way or another?
>
> Regards,
>
> /Pete
>
> PS: We got a merge in git as 2 of us were pushing into the repo around the
> same time
>
> From ecfdf70a08ae99b04050b00b752cc25728f1d537 Mon Sep 17 00:00:00 2001
> From: Pete Batard <address@hidden>
> Date: Wed, 25 Jan 2012 01:03:53 +0000
> Subject: [PATCH] Non LFS dependent fseeko detection and off_t truncation
> checks
>
> * On some systems, LFS may be enabled (64 bit off_t) but fseeko
> is not properly detected
> * When this occurs, seek will truncate off_t to long resulting
> in data corruption
> ---
> configure.ac | 15 +++++++++++++--
> lib/driver/_cdio_stdio.c | 8 ++++++++
> 2 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 4f124f2..0b76d39 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -167,8 +167,6 @@ if test "x$ac_cv_sys_largefiles" = "xyes"; then
> else
> LIBCDIO_LARGEFILE_FLAGS="-D_LARGE_FILES"
> fi
> - dnl AC_FUNC_FSEEKO sets HAVE_FSEEKO and $ac_cv_sys_largefile_source
> - AC_FUNC_FSEEKO
> if test "$ac_cv_sys_largefile_source" != no; then
> LIBCDIO_LARGEFILE_FLAGS="$LIBDDIO_LARGEFILE_FLAGS
> -D_LARGEFILE_SOURCE=$ac_cv_sys_largefile_source"
> fi
> @@ -508,6 +506,19 @@ AC_CHECK_FUNCS( [bzero chdir drand48 ftruncate
> geteuid getgid \
> seteuid setegid snprintf setenv strndup unsetenv tzset \
> sleep usleep vsnprintf readlink realpath gmtime_r
> localtime_r] )
>
> +# Check for fseeko() support (detection must not rely on LFS)
> +AC_MSG_CHECKING([for fseeko])
> +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
> +#ifdef HAVE_SYS_TYPES_H
> +#include <sys/types.h> /* for off_t */
> +#endif
> +#include <stdio.h>
> +],[int (*fp) (FILE *, off_t, int) = fseeko;
> +return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);])],
> +[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FSEEKO, 1,
> + [Define to 1 if you have the `fseeko' function.])],
> +[AC_MSG_RESULT(no)])
> +
> # check for timegm() support
> AC_CHECK_FUNC(timegm, AC_DEFINE(HAVE_TIMEGM,1,
> [Define to 1 if timegm is available]))
> diff --git a/lib/driver/_cdio_stdio.c b/lib/driver/_cdio_stdio.c
> index 1a3a1eb..1491d2d 100644
> --- a/lib/driver/_cdio_stdio.c
> +++ b/lib/driver/_cdio_stdio.c
> @@ -123,6 +123,14 @@ static driver_return_code_t
> _stdio_seek(void *p_user_data, off_t i_offset, int whence)
> {
> _UserData *const ud = p_user_data;
> +#ifndef HAVE_FSEEKO
> + /* Detect if off_t is lossy-truncated to long to avoid data corruption
> */
> + if ( (sizeof(off_t) > sizeof(long)) && (i_offset !=
> (off_t)((long)i_offset)) ) {
> + cdio_error ( STRINGIFY(STDIO_SEEK) " (): lossy truncation detected!");
> + errno = EFBIG;
> + return DRIVER_OP_ERROR;
> + }
> +#endif
>
> if ( (i_offset=STDIO_SEEK (ud->fd, i_offset, whence)) ) {
> cdio_error ( STRINGIFY(STDIO_SEEK) " (): %s", strerror (errno));
> --
> 1.7.8.msysgit.0
>
>
>