efe3be
From 4d827f0d75a53d3952288ab882efbddea7ffadfe Mon Sep 17 00:00:00 2001
efe3be
From: "djm@openbsd.org" <djm@openbsd.org>
efe3be
Date: Tue, 4 Apr 2017 00:24:56 +0000
efe3be
Subject: [PATCH] upstream commit
efe3be
efe3be
disallow creation (of empty files) in read-only mode;
efe3be
reported by Michal Zalewski, feedback & ok deraadt@
efe3be
efe3be
Upstream-ID: 5d9c8f2fa8511d4ecf95322994ffe73e9283899b
efe3be
---
efe3be
 sftp-server.c | 6 +++---
efe3be
 1 file changed, 3 insertions(+), 3 deletions(-)
efe3be
efe3be
diff --git a/sftp-server.c b/sftp-server.c
efe3be
index 3619cdfc0..df0fb5068 100644
efe3be
--- a/sftp-server.c
efe3be
+++ b/sftp-server.c
efe3be
@@ -1,4 +1,4 @@
efe3be
-/* $OpenBSD: sftp-server.c,v 1.110 2016/09/12 01:22:38 deraadt Exp $ */
efe3be
+/* $OpenBSD: sftp-server.c,v 1.111 2017/04/04 00:24:56 djm Exp $ */
efe3be
 /*
efe3be
  * Copyright (c) 2000-2004 Markus Friedl.  All rights reserved.
efe3be
  *
efe3be
@@ -691,8 +691,8 @@ process_open(u_int32_t id)
efe3be
 	logit("open \"%s\" flags %s mode 0%o",
efe3be
 	    name, string_from_portable(pflags), mode);
efe3be
 	if (readonly &&
efe3be
-	    ((flags & O_ACCMODE) == O_WRONLY ||
efe3be
-	    (flags & O_ACCMODE) == O_RDWR)) {
efe3be
+	    ((flags & O_ACCMODE) != O_RDONLY ||
efe3be
+	    (flags & (O_CREAT|O_TRUNC)) != 0)) {
efe3be
 		verbose("Refusing open request in read-only mode");
efe3be
 		status = SSH2_FX_PERMISSION_DENIED;
efe3be
 	} else {
efe3be