mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] DAC960: Fix undefined behavior on empty string
@ 2009-07-19 13:05 Michael Buesch
  2009-07-23 21:26 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Buesch @ 2009-07-19 13:05 UTC (permalink / raw)
  To: linux-kernel

This patch fixes undefined behavior due to buffer underrun,
if an empty string is written to the proc file.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: stable@kernel.org

---

This patch is untested, because I do not have the hardware.

---
 drivers/block/DAC960.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- linux-2.6.orig/drivers/block/DAC960.c
+++ linux-2.6/drivers/block/DAC960.c
@@ -6555,21 +6555,21 @@ static int DAC960_ProcWriteUserCommand(s
 				       const char __user *Buffer,
 				       unsigned long Count, void *Data)
 {
   DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
   unsigned char CommandBuffer[80];
   int Length;
   if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
   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)
 	    ? Count : -EBUSY);
   else
     return (DAC960_V2_ExecuteUserCommand(Controller, CommandBuffer)
 	    ? Count : -EBUSY);
 }
 
 

-- 
Greetings, Michael.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-07-23 21:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-19 13:05 [PATCH] DAC960: Fix undefined behavior on empty string Michael Buesch
2009-07-23 21:26 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome