[#75225] [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7) — k@...
Issue #12324 has been reported by Kazuki Yamaguchi.
6 messages
2016/04/27
[#78693] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Eric Wong <normalperson@...>
2016/12/17
k@rhe.jp wrote:
[#78701] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Kazuki Yamaguchi <k@...>
2016/12/17
On Sat, Dec 17, 2016 at 01:31:12AM +0000, Eric Wong wrote:
[#78702] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Eric Wong <normalperson@...>
2016/12/17
Kazuki Yamaguchi <k@rhe.jp> wrote:
[ruby-core:75080] [Ruby trunk Bug#12307] File.new and File.open change permissions even if the file exists on Windows
From:
usa@...
Date:
2016-04-21 23:00:02 UTC
List:
ruby-core #75080
Issue #12307 has been updated by Usaku NAKAMURA.
> Does open(2) in MSVCRT causes this bug?
No.
Ruby always call `open(2)` with `O_CREAT` when opening files with `"w"`.
On a simple level, ruby's `File.open("abc", "w", 0666)` is translated into C's `open("abc", O_CREAT | O_TRUNC | O_RDONLY, 0666)`.
Ok, let me show what is happening with MSVCRT.
file open.c:
```C
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
main(void)
{
int flags = _O_CREAT | _O_TRUNC | _O_WRONLY;
int fd = _open("abc", flags, 0666);
struct _stat stat;
if (fd == -1) {
printf("error(open 1) %d\n", errno);
exit(1);
}
if (_fstat(fd, &stat)) {
printf("error(fstat 1) %d\n", errno);
exit(1);
}
printf("%o\n", stat.st_mode);
close(fd);
fd = _open("abc", flags, 0466);
if (fd == -1) {
printf("error(open 2) %d\n", errno);
exit(1);
}
if (_fstat(fd, &stat)) {
printf("error(fstat 2) %d\n", errno);
exit(1);
}
printf("%o\n", stat.st_mode);
close(fd);
}
```
Result:
```
D:\test> cl -MD open.c
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.40219.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
open.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:open.exe
open.obj
D:\test> open
100666
100444
```
----------------------------------------
Bug #12307: File.new and File.open change permissions even if the file exists on Windows
https://bugs.ruby-lang.org/issues/12307#change-58203
* Author: Benoit Daloze
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
For instance:
~~~
# New file
File.open("abc", "w", 0666) { |f|
puts f.stat.mode.to_s(8) # => 100666, OK
}
# File exists
File.open("abc", "w", 0466) { |f|
puts f.stat.mode.to_s(8) # => 100444, BUG
}
~~~
So the mode of the file was changed even though the file already exists.
This is inconsistent with the behavior on other platforms such as UNIX which only consider mode for new files.
open(2) is fairly clear about this on Linux and OS X: "if neither O_CREAT nor O_TMPFILE is specified, then mode is ignored".
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>