From 4487cc5a9622d40fb74f2df5cb026438772af5a5 Mon Sep 17 00:00:00 2001 From: guenther Date: Sat, 14 May 2022 05:06:32 +0000 Subject: [PATCH] Use fseeko() instead of fseek() inside libc, as the latter just calls the former with a loss of range. Mark fseek symbol as deprecated to block accidental use in the future. ok millert@ deraadt@ --- lib/libc/gen/getcap.c | 4 ++-- lib/libc/hidden/stdio.h | 4 ++-- lib/libc/rpc/xdr_stdio.c | 4 ++-- lib/libc/stdio/fseek.c | 3 +-- lib/libc/stdio/rewind.c | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index af866d26cc1..5af3c40d04d 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcap.c,v 1.35 2019/07/03 03:24:04 deraadt Exp $ */ +/* $OpenBSD: getcap.c,v 1.36 2022/05/14 05:06:32 guenther Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -244,7 +244,7 @@ getent(char **cap, u_int *len, char **db_array, FILE *fp, * Open database if not already open. */ if (fp != NULL) { - (void)fseek(fp, 0L, SEEK_SET); + fseeko(fp, 0, SEEK_SET); myfd = 0; opened++; } else { diff --git a/lib/libc/hidden/stdio.h b/lib/libc/hidden/stdio.h index 6b03f7ac54e..a40a4b45c1d 100644 --- a/lib/libc/hidden/stdio.h +++ b/lib/libc/hidden/stdio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stdio.h,v 1.7 2016/09/06 19:56:36 guenther Exp $ */ +/* $OpenBSD: stdio.h,v 1.8 2022/05/14 05:06:32 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther * @@ -65,7 +65,7 @@ PROTO_NORMAL(fputs); PROTO_NORMAL(fread); PROTO_NORMAL(freopen); PROTO_NORMAL(fscanf); -PROTO_NORMAL(fseek); +PROTO_STD_DEPRECATED(fseek); PROTO_NORMAL(fseeko); PROTO_NORMAL(fsetpos); PROTO_NORMAL(ftell); diff --git a/lib/libc/rpc/xdr_stdio.c b/lib/libc/rpc/xdr_stdio.c index 692dcf99a1b..00984136c7b 100644 --- a/lib/libc/rpc/xdr_stdio.c +++ b/lib/libc/rpc/xdr_stdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xdr_stdio.c,v 1.16 2022/02/14 03:38:59 guenther Exp $ */ +/* $OpenBSD: xdr_stdio.c,v 1.17 2022/05/14 05:06:32 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -144,7 +144,7 @@ static bool_t xdrstdio_setpos(XDR *xdrs, u_int pos) { - return ((fseek((FILE *)xdrs->x_private, (long)pos, SEEK_SET) == -1) ? + return ((fseeko((FILE *)xdrs->x_private, pos, SEEK_SET) == -1) ? FALSE : TRUE); } diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 1d0895a819a..18c530138a6 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fseek.c,v 1.13 2019/06/28 13:32:42 deraadt Exp $ */ +/* $OpenBSD: fseek.c,v 1.14 2022/05/14 05:06:32 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -250,4 +250,3 @@ fseek(FILE *fp, long offset, int whence) { return (fseeko(fp, offset, whence)); } -DEF_STRONG(fseek); diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index 4a52ed064a5..63dacc3a232 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rewind.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: rewind.c,v 1.7 2022/05/14 05:06:32 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -37,7 +37,7 @@ void rewind(FILE *fp) { - (void) fseek(fp, 0L, SEEK_SET); + fseeko(fp, 0, SEEK_SET); clearerr(fp); errno = 0; /* not required, but seems reasonable */ } -- 2.20.1