]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/tst-ofdlocks.c
1 /* Check non representable OFD locks regions in non-LFS mode (BZ #20251)
2 Copyright (C) 2018 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include <support/temp_file.h>
24 #include <support/check.h>
26 static char *temp_filename
;
30 do_prepare (int argc
, char **argv
)
32 temp_fd
= create_temp_file ("tst-ofdlocks.", &temp_filename
);
33 TEST_VERIFY_EXIT (temp_fd
!= -1);
36 #define PREPARE do_prepare
41 /* It first allocates a open file description lock range which can not
42 be represented in a 32 bit struct flock. */
43 struct flock64 lck64
= {
46 .l_start
= (off64_t
)INT32_MAX
+ 1024,
49 TEST_VERIFY_EXIT (fcntl64 (temp_fd
, F_OFD_SETLKW
, &lck64
) == 0);
51 /* Open file description locks placed through the same open file description
52 (either by same file descriptor or a duplicated one created by fork,
53 dup, fcntl F_DUPFD, etc.) overwrites then old lock. To force a
54 conflicting lock combination, it creates a new file descriptor. */
55 int fd
= open64 (temp_filename
, O_RDWR
, 0666);
56 TEST_VERIFY_EXIT (fd
!= -1);
58 /* It tries then to allocate another open file descriptior with a valid
59 non-LFS bits struct flock but which will result in a conflicted region
60 which can not be represented in a non-LFS struct flock. */
64 .l_start
= INT32_MAX
- 1024,
67 int r
= fcntl (fd
, F_OFD_GETLK
, &lck
);
68 if (sizeof (off_t
) != sizeof (off64_t
))
69 TEST_VERIFY (r
== -1 && errno
== EOVERFLOW
);
76 #include <support/test-driver.c>