GNU bug report logs -
#33287
[PATCH] sync: add missing brackets in sync_arg()
Previous Next
Reported by: Kamil Dudka <kdudka <at> redhat.com>
Date: Tue, 6 Nov 2018 12:04:01 UTC
Severity: normal
Tags: patch
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 33287 in the body.
You can then email your comments to 33287 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#33287
; Package
coreutils
.
(Tue, 06 Nov 2018 12:04:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Kamil Dudka <kdudka <at> redhat.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Tue, 06 Nov 2018 12:04:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Detected by Coverity Analysis:
Error: RESOURCE_LEAK (CWE-772):
coreutils-8.30/src/sync.c:112: open_fn: Returning handle opened by "open".
coreutils-8.30/src/sync.c:112: var_assign: Assigning: "fd" = handle returned from "open(file, 2049)".
coreutils-8.30/src/sync.c:115: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
113| if (fd < 0)
114| error (0, rd_errno, _("error opening %s"), quoteaf (file));
115|-> return false;
116| }
117|
---
src/sync.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/sync.c b/src/sync.c
index bd3671a19..607fa8f7f 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -111,8 +111,10 @@ sync_arg (enum sync_mode mode, char const *file)
if (open_flags != (O_WRONLY | O_NONBLOCK))
fd = open (file, O_WRONLY | O_NONBLOCK);
if (fd < 0)
- error (0, rd_errno, _("error opening %s"), quoteaf (file));
- return false;
+ {
+ error (0, rd_errno, _("error opening %s"), quoteaf (file));
+ return false;
+ }
}
/* We used O_NONBLOCK above to not hang with fifos,
--
2.17.2
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Tue, 06 Nov 2018 18:37:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Kamil Dudka <kdudka <at> redhat.com>
:
bug acknowledged by developer.
(Tue, 06 Nov 2018 18:37:02 GMT)
Full text and
rfc822 format available.
Message #10 received at 33287-done <at> debbugs.gnu.org (full text, mbox):
Thanks, I installed that and am closing the bug report.
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#33287
; Package
coreutils
.
(Tue, 06 Nov 2018 23:35:01 GMT)
Full text and
rfc822 format available.
Message #13 received at 33287 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 11/6/18 7:35 PM, Paul Eggert wrote:
> Thanks, I installed that and am closing the bug report.
That was a real bug, i.e., not only a resource leak, wasn't it?
If the calling user has -r+w permissions on the file, then sync previously
exited with 1 without actually syncing:
$ install -m 0200 /dev/null /tmp/file
$ ls -log /tmp/file
--w------- 1 0 Nov 7 00:06 /tmp/file
$ strace -v /usr/bin/sync /tmp/file 2>&1 | tail -n6
openat(AT_FDCWD, "/tmp/file", O_RDONLY|O_NONBLOCK) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "/tmp/file", O_WRONLY|O_NONBLOCK) = 3
close(1) = 0
close(2) = 0
exit_group(1) = ?
+++ exited with 1 +++
With the patch, fsync is called, and sync terminated with success:
$ strace -v src/sync /tmp/file 2>&1 | tail
openat(AT_FDCWD, "/tmp/file", O_RDONLY|O_NONBLOCK) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "/tmp/file", O_WRONLY|O_NONBLOCK) = 3
fcntl(3, F_GETFL) = 0x8801 (flags O_WRONLY|O_NONBLOCK|O_LARGEFILE)
fcntl(3, F_SETFL, O_WRONLY|O_LARGEFILE) = 0
fsync(3) = 0
close(3) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
Should we add a NEWS entry and a test - see attached?
Thanks & have a nice day,
Berny
[0001-sync-add-NEWS-and-test-for-the-fix-in-the-previous-c.patch (text/x-patch, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#33287
; Package
coreutils
.
(Wed, 07 Nov 2018 01:03:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 33287 <at> debbugs.gnu.org (full text, mbox):
On 11/6/18 3:33 PM, Bernhard Voelker wrote:
> Should we add a NEWS entry and a test - see attached?
Thanks, good point, and I installed that.
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#33287
; Package
coreutils
.
(Wed, 07 Nov 2018 08:25:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 33287 <at> debbugs.gnu.org (full text, mbox):
On Wednesday, November 7, 2018 12:33:45 AM CET Bernhard Voelker wrote:
> On 11/6/18 7:35 PM, Paul Eggert wrote:
> > Thanks, I installed that and am closing the bug report.
>
> That was a real bug, i.e., not only a resource leak, wasn't it?
>
> If the calling user has -r+w permissions on the file, then sync previously
> exited with 1 without actually syncing:
>
> $ install -m 0200 /dev/null /tmp/file
>
> $ ls -log /tmp/file
> --w------- 1 0 Nov 7 00:06 /tmp/file
>
> $ strace -v /usr/bin/sync /tmp/file 2>&1 | tail -n6
> openat(AT_FDCWD, "/tmp/file", O_RDONLY|O_NONBLOCK) = -1 EACCES (Permission
> denied) openat(AT_FDCWD, "/tmp/file", O_WRONLY|O_NONBLOCK) = 3
> close(1) = 0
> close(2) = 0
> exit_group(1) = ?
> +++ exited with 1 +++
>
> With the patch, fsync is called, and sync terminated with success:
>
> $ strace -v src/sync /tmp/file 2>&1 | tail
> openat(AT_FDCWD, "/tmp/file", O_RDONLY|O_NONBLOCK) = -1 EACCES (Permission
> denied) openat(AT_FDCWD, "/tmp/file", O_WRONLY|O_NONBLOCK) = 3
> fcntl(3, F_GETFL) = 0x8801 (flags
> O_WRONLY|O_NONBLOCK|O_LARGEFILE) fcntl(3, F_SETFL, O_WRONLY|O_LARGEFILE) =
> 0
> fsync(3) = 0
> close(3) = 0
> close(1) = 0
> close(2) = 0
> exit_group(0) = ?
> +++ exited with 0 +++
>
> Should we add a NEWS entry and a test - see attached?
Looks good. Thanks for the follow-up patch!
Kamil
> Thanks & have a nice day,
> Berny
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 05 Dec 2018 12:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 6 years and 282 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.