From: Michael Buesch Date: Tue, 22 Sep 2009 23:43:36 +0000 (-0700) Subject: dac960: fix undefined behavior on empty string X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e898893399335514b10dfbd75598f8308976abe4;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git dac960: fix undefined behavior on empty string Fix undefined behavior due to a buffer underrun if an empty string is written to the proc file. Signed-off-by: Michael Buesch Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c index c77b6f3c28ea..6fa7b0fdbdfd 100644 --- a/drivers/block/DAC960.c +++ b/drivers/block/DAC960.c @@ -6562,7 +6562,7 @@ static int DAC960_ProcWriteUserCommand(struct file *file, if (copy_from_user(CommandBuffer, Buffer, Count)) return -EFAULT; CommandBuffer[Count] = '\0'; Length = strlen(CommandBuffer); - if (CommandBuffer[Length-1] == '\n') + if (Length > 0 && CommandBuffer[Length-1] == '\n') CommandBuffer[--Length] = '\0'; if (Controller->FirmwareType == DAC960_V1_Controller) return (DAC960_V1_ExecuteUserCommand(Controller, CommandBuffer)