dasd_get_user_string() strips a trailing newline by looking at the last
byte that was written. For an empty write that's the byte in front of
the buffer it just allocated. Only look if something was written.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: [email protected]
Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 drivers/s390/block/dasd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 2ffe404b890f..e97891e58957 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -933,7 +933,7 @@ char *dasd_get_user_string(const char __user *user_buf, 
size_t user_len)
                return ERR_PTR(-EFAULT);
        }
        /* got the string, now strip linefeed. */
-       if (buffer[user_len - 1] == '\n')
+       if (user_len && buffer[user_len - 1] == '\n')
                buffer[user_len - 1] = 0;
        else
                buffer[user_len] = 0;

-- 
2.53.0


Reply via email to