• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision4f506bb95ad4bc55e6174cef98803802a35b050e (tree)
Time2019-06-21 19:09:36
AuthorDenys Vlasenko <dvlasenk@redh...>
CommiterWaldemar Brodkorb

Log Message

fix opendir, fpathconf and ttyname_r to use fstat64(), not fstat()

There is no opendir64(), thus even programs built for 64-bit off_t
use opendir(). Before this change, internally opendir() uses fstat(),
with the following breakage if some of struct stat fields are too narrow:

$ strace ls -l
execve("/busybox/ls", ["ls", "-l"], 0x7ffcdc43ede8 /* 16 vars */) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
getuid32() = 0
time([1551486393 /* 2019-03-02T00:26:33+0000 */]) = 1551486393 (2019-03-02T00:26:33+0000)
ioctl(0, TIOCGWINSZ, {ws_row=38, ws_col=120, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
brk(NULL) = 0x9768000
brk(0x9769000) = 0x9769000
lstat64(".", 0xffa6e374) = 0
open(".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, 0xffa6e378) = -1 EOVERFLOW (Value too large for defined data type)

See https://bugs.busybox.net/show_bug.cgi?id=11651

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>

Change Summary

Incremental Difference

--- a/libc/misc/dirent/opendir.c
+++ b/libc/misc/dirent/opendir.c
@@ -16,6 +16,9 @@
1616 #include <dirent.h>
1717 #include "dirstream.h"
1818
19+#define STAT stat64
20+#define FSTAT fstat64
21+
1922 static DIR *fd_to_DIR(int fd, __blksize_t size)
2023 {
2124 DIR *ptr;
@@ -43,9 +46,9 @@ static DIR *fd_to_DIR(int fd, __blksize_t size)
4346 DIR *fdopendir(int fd)
4447 {
4548 int flags;
46- struct stat st;
49+ struct STAT st;
4750
48- if (fstat(fd, &st))
51+ if (FSTAT(fd, &st))
4952 return NULL;
5053 if (!S_ISDIR(st.st_mode)) {
5154 __set_errno(ENOTDIR);
@@ -69,12 +72,12 @@ DIR *fdopendir(int fd)
6972 DIR *opendir(const char *name)
7073 {
7174 int fd;
72- struct stat statbuf;
75+ struct STAT statbuf;
7376 DIR *ptr;
7477
7578 #ifndef O_DIRECTORY
7679 /* O_DIRECTORY is linux specific and has been around since like 2.1.x */
77- if (stat(name, &statbuf))
80+ if (STAT(name, &statbuf))
7881 return NULL;
7982 if (!S_ISDIR(statbuf.st_mode)) {
8083 __set_errno(ENOTDIR);
@@ -90,7 +93,7 @@ DIR *opendir(const char *name)
9093 * defined and since Linux has supported it for like ever, i'm not going
9194 * to worry about it right now (if ever). */
9295
93- if (fstat(fd, &statbuf) < 0) {
96+ if (FSTAT(fd, &statbuf) < 0) {
9497 /* this close() never fails
9598 *int saved_errno;
9699 *saved_errno = errno; */
--- a/libc/termios/ttyname.c
+++ b/libc/termios/ttyname.c
@@ -31,6 +31,9 @@
3131 #include <dirent.h>
3232 #include <sys/stat.h>
3333
34+#define STAT stat64
35+#define FSTAT fstat64
36+#define LSTAT lstat64
3437
3538 #define TTYNAME_BUFLEN 32
3639
@@ -45,8 +48,8 @@ static const char dirlist[] =
4548 int ttyname_r(int fd, char *ubuf, size_t ubuflen)
4649 {
4750 struct dirent *d;
48- struct stat st;
49- struct stat dst;
51+ struct STAT st;
52+ struct STAT dst;
5053 const char *p;
5154 char *s;
5255 DIR *fp;
@@ -54,7 +57,7 @@ int ttyname_r(int fd, char *ubuf, size_t ubuflen)
5457 size_t len;
5558 char buf[TTYNAME_BUFLEN];
5659
57- if (fstat(fd, &st) < 0) {
60+ if (FSTAT(fd, &st) < 0) {
5861 return errno;
5962 }
6063
@@ -86,7 +89,7 @@ int ttyname_r(int fd, char *ubuf, size_t ubuflen)
8689
8790 strcpy(s, d->d_name);
8891
89- if ((lstat(buf, &dst) == 0)
92+ if ((LSTAT(buf, &dst) == 0)
9093 #if 0
9194 /* Stupid filesystems like cramfs fail to guarantee that
9295 * st_ino and st_dev uniquely identify a file, contrary to
--- a/libc/unistd/fpathconf.c
+++ b/libc/unistd/fpathconf.c
@@ -24,6 +24,8 @@
2424 #include <sys/stat.h>
2525 #include <sys/statfs.h>
2626
27+#define STAT stat64
28+#define FSTAT fstat64
2729
2830 #ifndef __USE_FILE_OFFSET64
2931 extern int fstatfs (int __fildes, struct statfs *__buf)
@@ -205,9 +207,9 @@ long int fpathconf(int fd, int name)
205207 #if defined _POSIX_ASYNC_IO
206208 {
207209 /* AIO is only allowed on regular files and block devices. */
208- struct stat st;
210+ struct STAT st;
209211
210- if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
212+ if (FSTAT (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
211213 return -1;
212214 else
213215 return 1;