Page MenuHome GnuPG

Portability issue: ftruncate
Closed, ResolvedPublic

Description

In gnupg/agent/findkey.c we use ftruncate in non-portable way.

IIUC, for portability, es_fflush is required before calling ftruncate.

I encountered an error of gpg-agent (with EFBIG) creating private keys, when a peculiar situation (of using Wine to test gpg-agent.exe on GNU/Linux).

I wonder if Solaris works well.

https://www.man7.org/linux/man-pages/man3/ftruncate.3p.html
https://docs.oracle.com/cd/E19683-01/817-0692/6mgfnkuf8/index.html

Related Objects

Event Timeline

iirc, we use ftruncate for ages now. The problem with the name ftruncate is that it looks to similar to the stdio functions. But sure, things should be flushed first.

werner triaged this task as Normal priority.Jun 20 2022, 1:08 PM

I created minimized test:

I'm using mingw-w64 10.0.0-2 from Debian testing:

$ i686-w64-mingw32-gcc --version
i686-w64-mingw32-gcc (GCC) 10-win32 20210110

With no -D_FILE_OFFSET_BITS=64, it works well (with ftruncate).

Using Wine, it seems that GetDiskFreeSpaceExW fails.
Then, with -D_FILE_OFFSET_BITS=64, it fails, beacuse in this case ftruncate64 in this version of MinGW behaves like POSIX version of ftruncate.

$ i686-w64-mingw32-gcc -D_FILE_OFFSET_BITS=64 -g ftruncate-check.c
$ ./a.exe
FTELLO: 21 0
FTRUNCATE: 21 27 (-1)
ftruncate fail: File too large

Wine 5.0.3 (on Debian bullseye) fails.
Wine 6.0.3 Debian testing does no failure.

Looking illumos-gate, Solaris variants have no issues.

Even if it is only a single case (of old version of Wine), I think that it is worth to add es_fflush when writing to file.

I'm going to add it to master.

gniibe edited projects, added backport; removed Restricted Project.Jul 18 2022, 9:58 AM

It's in 2.3.7 and 2.2.36.

gniibe claimed this task.