mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Mathias Lang <mathias.lang@bpfkorea.org>
To: musl@lists.openwall.com
Subject: [BUG] fseek behavior differs on whence parameter
Date: Wed, 23 Oct 2019 14:48:21 +0900	[thread overview]
Message-ID: <CAHBuF8Gek5xFw0vmAnNDaqJtaedd4gz=rWobsPnCikdnC+3vCA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1346 bytes --]

Hi everyone,
As part of my recent effort to get the D Programming Language (
https://dlang.org/) to work on Alpine Linux, I've hit what I believe is a
bug in Musl.
Dlang relies heavily on libc, and obviously is historically glibc-based on
POSIX.

When porting to Alpine/Musl, one of the unittests that failed is calling
`fseek` with the value '3' for whence. The call is expected to fail, and it
does on Glibc, but succeed on Musl.
The reason for this difference is that Musl just forwards its whence
argument to the lseek syscall, which accepts '3' (aka SEEK_DATA) as a
parameter.

However, glibc explicitly checks for if the value is one of SEEK_SET,
SEEK_END, SEEK_CUR (
https://github.com/lattera/glibc/blob/895ef79e04a953cac1493863bcae29ad85657ee1/libio/ioseekoff.c#L32-L38),
and POSIX defines the function as setting errno to EINVAL if the "whence
argument is invalid" (
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html). The
only man page I could find that mentions 'SEEK_{DATA,HOLE}' is `lseek`'s.

In light of this, it looks to me like Musl behavior is the one that should
be changed.

For reference, original discussions:
- https://github.com/alpinelinux/aports/pull/11931#issuecomment-544831142
- https://github.com/dlang/phobos/pull/7244#issuecomment-545256706


P.S: I am not subscribed to the ML, please CC me.

[-- Attachment #2: Type: text/html, Size: 1859 bytes --]

             reply	other threads:[~2019-10-23  5:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23  5:48 Mathias Lang [this message]
2019-10-23 11:45 ` Rich Felker
2019-10-24 14:06   ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHBuF8Gek5xFw0vmAnNDaqJtaedd4gz=rWobsPnCikdnC+3vCA@mail.gmail.com' \
    --to=mathias.lang@bpfkorea.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).