vfs: fail write_stat() on file descriptors opened read-only.
Change-Id: I20d586c606c47df6625cc9272f153250a5a621d6 Reviewed-on: https://review.haiku-os.org/706 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
9cc0f06a01
commit
8c053e955e
@@ -6562,6 +6562,9 @@ common_write_stat(struct file_descriptor* descriptor, const struct stat* stat,
|
||||
FUNCTION(("common_write_stat(vnode = %p, stat = %p, statMask = %d)\n",
|
||||
vnode, stat, statMask));
|
||||
|
||||
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (!HAS_FS_CALL(vnode, write_stat))
|
||||
return B_READ_ONLY_DEVICE;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -48,5 +49,19 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "%s: could open the file read-only \"%s\": %s\n",
|
||||
__progname, argv[1], strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (ftruncate(fd, newSize) == 0 || errno != EINVAL) {
|
||||
fprintf(stderr, "%s: could truncate a file opened read-only \"%s\": %s\n",
|
||||
__progname, argv[1], strerror(errno));
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user