kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Incorrect mode in file creation #635

Closed bakul closed 1 year ago

bakul commented 1 year ago

In the following 4 places the mode argument should be 0777 not 07777.

src/0.c:587:  I f=open(e,O_RDWR|O_CREAT|O_TRUNC,07777);
src/0.c:1130:  I f=open(e,O_RDWR,07777); //Try the extended version of the filename first
src/0.c:1132:  else {f=open(m,O_RDWR,07777); stat(m,&c);} //Then try the plain version
src/0.c:1225:  I f=m[0]?open(m,O_RDWR|O_CREAT|(append ?0:O_TRUNC),07777):1; //stdout if m is ` or "" or "\000..."

The effect on FreeBSD is to set the suid and sgid bits. For example, I get this:

$ ./k
kona      \ for help. \\ to exit.

  "file" 1:("a";4 5)
  \\
15:01:56 server1:~/lang/kona 10704: ls -l file*
-rwsr-sr-x  1 bakul  bakul  112 Nov  2 15:01 file.K

Note the s instead x for user and group.

Another issue is that the file extension should be .l but it is .K on FreeBSD and Linux. It is correct on macOS.

bakul commented 1 year ago

Forgot to mention that since file 1: expr creates a data file, it should not have the execute permission set. k3 handles this correctly.