diff mbox

HID: picoLCD: off by one in dump_buff_as_hex()

Message ID 20120914110414.GA1152@elgon.mountain (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Dan Carpenter Sept. 14, 2012, 11:04 a.m. UTC
We're placing the NUL terminator one character beyond the end of the
buffer here.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This change obviously don't make the code worse, but I'm not positive
it's the right fix.  I'm not sure the lines before are doing the right
thing either, if we had two chars of remaining space then wouldn't it be
better to put the new line and NUL in the unused space?

If you decide to do it differently, then please feel to sent a patch for
that and give me a Reported-by cookie.

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bruno Prémont Sept. 17, 2012, 8:54 p.m. UTC | #1
Hi Dan,

On Fri, 14 September 2012 Dan Carpenter <dan.carpenter@oracle.com> wrote:
> We're placing the NUL terminator one character beyond the end of the
> buffer here.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This change obviously don't make the code worse, but I'm not positive
> it's the right fix.  I'm not sure the lines before are doing the right
> thing either, if we had two chars of remaining space then wouldn't it be
> better to put the new line and NUL in the unused space?

The output buffer full should not happen as the 256 bytes buffer can hold
more than the max expected report size of 64 bytes.

An option would be to convert to hex_dump_to_buffer(), but as this happens
partially under IRQ context - even though for debugging purposes - the
switch may be a bit too expensive, especially as one still has to append
linefeed after it.


I think I will extend your fix slightly in order to cover "too much input"
in a way visible to /sys/kernel/hid/*/events reader (for the case that
reports would grow in size).

Though no need to check for minimal output buffer size as callers are local
and feed in #defined sized buffer.


More on Wednesday evening, too late today and no time tomorrow.

Bruno

> If you decide to do it differently, then please feel to sent a patch for
> that and give me a Reported-by cookie.
> 
> diff --git a/drivers/hid/hid-picolcd_debugfs.c b/drivers/hid/hid-picolcd_debugfs.c
> index eec85b5..ff271ff0 100644
> --- a/drivers/hid/hid-picolcd_debugfs.c
> +++ b/drivers/hid/hid-picolcd_debugfs.c
> @@ -390,7 +390,7 @@ static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
>  		dst[j--] = '\0';
>  		dst[j] = '\n';
>  	} else
> -		dst[j] = '\0';
> +		dst[dst_sz - 1] = '\0';
>  }
>  
>  void picolcd_debug_out_report(struct picolcd_data *data,
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hid/hid-picolcd_debugfs.c b/drivers/hid/hid-picolcd_debugfs.c
index eec85b5..ff271ff0 100644
--- a/drivers/hid/hid-picolcd_debugfs.c
+++ b/drivers/hid/hid-picolcd_debugfs.c
@@ -390,7 +390,7 @@  static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
 		dst[j--] = '\0';
 		dst[j] = '\n';
 	} else
-		dst[j] = '\0';
+		dst[dst_sz - 1] = '\0';
 }
 
 void picolcd_debug_out_report(struct picolcd_data *data,