Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1689608

Re: [PATCH v2 2/2] staging: gs_fpgaboot: change char to u8

From Jacob von Chorus <jacobvonchorus@cwphoto.ca>
Newsgroups linux.kernel
Subject Re: [PATCH v2 2/2] staging: gs_fpgaboot: change char to u8
Date 2017-07-18 04:00 +0200
Message-ID <u4pXP-4sz-3@gated-at.bofh.it> (permalink)
References <u4oS5-3KB-5@gated-at.bofh.it> <u4oS6-3KB-17@gated-at.bofh.it> <u4puO-4ho-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Jul 17, 2017 at 06:22:08PM -0700, Joe Perches wrote:
> read_bitstream takes an int rdsize, not a u16.
> and this function will overflow tbuf if len > 64
>
> static void readinfo_bitstream(char *bitdata, char *buf, int *offset)
> {
> 	char tbuf[64];
> 	s32 len;
> 
> 	/* read section char */
> 	read_bitstream(bitdata, tbuf, offset, 1);
> 
> 	/* read length */
> 	read_bitstream(bitdata, tbuf, offset, 2);
> 
> 	len = tbuf[0] << 8 | tbuf[1];
> 
> 	read_bitstream(bitdata, buf, offset, len);
> 	buf[len] = '\0';
> }
> 
> len is up to 64k but tbuf is 64 bytes.

tbuf is used here to read a total of 3 bytes over two calls to
read_bitstream. The larger read of size, len, is stored to buf which is
MAX_STR bytes in length. 

> 	len = get_unaligned_le16(tbuf)
> 
> might be nicer than
> 
> 	len = tbuf[0] << 8 | tbuf[1];

Agreed, though it should be "get_unaligned_be16". 

Thanks.

Regards,
Jacob von Chorus

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 1/2] staging: gs_fpgaboot: add buffer overflow checks Jacob von Chorus <jacobvonchorus@cwphoto.ca> - 2017-07-18 02:50 +0200
  [PATCH v2 2/2] staging: gs_fpgaboot: change char to u8 Jacob von Chorus <jacobvonchorus@cwphoto.ca> - 2017-07-18 02:50 +0200
    Re: [PATCH v2 2/2] staging: gs_fpgaboot: change char to u8 Joe Perches <joe@perches.com> - 2017-07-18 03:30 +0200
      Re: [PATCH v2 2/2] staging: gs_fpgaboot: change char to u8 Jacob von Chorus <jacobvonchorus@cwphoto.ca> - 2017-07-18 04:00 +0200
  Re: [PATCH v2 1/2] staging: gs_fpgaboot: add buffer overflow checks Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-18 09:10 +0200
  Re: [PATCH v2 1/2] staging: gs_fpgaboot: add buffer overflow checks Dan Carpenter <dan.carpenter@oracle.com> - 2017-07-18 11:20 +0200

csiph-web