linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
To: libc-help@sourceware.org
Cc: linux-man <linux-man@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Subject: Re: Possible bug in getdents64()?
Date: Thu, 29 Oct 2020 12:04:13 +0100	[thread overview]
Message-ID: <01065580-8602-52e6-0cca-22d1aa20a540@gmail.com> (raw)
In-Reply-To: <829387c9-50d7-3d29-83bf-c4fec17cf9dd@gmail.com>

[[ CC += linux-man, linux-kernel, libc-alpha, mtk ]]

On 2020-10-28 20:26, Alejandro Colomar wrote:
> The manual page for getdents64() says the prototype should be the 
> following:
> 
>         int getdents64(unsigned int fd, struct linux_dirent64 *dirp,
>                      unsigned int count);
> 
> 
> Note the type of 'count': 'unsigned int'
> (usually a 32-bit unsigned integer).
> And the Linux kernel seems to use those types (fs/readdir.c:351):
> 
> SYSCALL_DEFINE3(getdents64, unsigned int, fd,
>          struct linux_dirent64 __user *, dirent,
>          unsigned int, count)
> {
> ...
> }
> 
> But glibc uses 'size_t' (usually a 64-bit unsigned integer)
> for the parameter 'count' (sysdeps/unix/linux/getdents64.c:25):
> 
> 
> /* The kernel struct linux_dirent64 matches the 'struct dirent64' type.  */
> ssize_t
> __getdents64 (int fd, void *buf, size_t nbytes)
> {
>    /* The system call takes an unsigned int argument, and some length
>       checks in the kernel use an int type.  */
>    if (nbytes > INT_MAX)
>      nbytes = INT_MAX;
>    return INLINE_SYSCALL_CALL (getdents64, fd, buf, nbytes);
> }
> libc_hidden_def (__getdents64)
> weak_alias (__getdents64, getdents64)
> 
> 
> 
> Isn't it undefined behavior to pass a variable of a different (larger) 
> type to a variadic function than what it expects?
> 
> Is that behavior defined in this implementation?
> 
> Wouldn't a cast to 'unsigned int' be needed?
> 
> 
> Thanks,
> 
> Alex

       reply	other threads:[~2020-10-29 11:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <829387c9-50d7-3d29-83bf-c4fec17cf9dd@gmail.com>
2020-10-29 11:04 ` Alejandro Colomar [this message]
2020-10-29 11:09   ` Possible bug in getdents64()? Florian Weimer
2020-10-29 11:12     ` Alejandro Colomar

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=01065580-8602-52e6-0cca-22d1aa20a540@gmail.com \
    --to=colomar.6.4.3@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=libc-help@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.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.
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).