IIO: Documentation: generic_buffer example: Avoid NULL pointer dereference
Subsystems (3)
PATCH 1/6 IIO: Documentation: generic_buffer example: Avoid NULL pointer dereference
From: Michael Hennerich <[email protected]>
In case optarg n is not given return/exit
--- drivers/staging/iio/Documentation/generic_buffer.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/staging/iio/Documentation/generic_buffer.c +3 -0
@@ -168,6 +168,9 @@ int main(int argc, char **argv) } } +if (device_name ==NULL ) +return -1 ; +/* Find the device requested */ dev_num =find_type_by_name (device_name,"device" );if (dev_num <0 ) {
--
1.6.0.2
PATCH 2/6 IIO: Documentation: iio_utils: Avoid double free()
From: Michael Hennerich <[email protected]>
filename is used and freed later
--- drivers/staging/iio/Documentation/iio_utils.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/staging/iio/Documentation/iio_utils.h +0 -1
@@ -319,7 +319,6 @@ inline int build_channel_array(const char *device_dir, }fscanf (sysfsfp,"%u" , ¤t->enabled);fclose (sysfsfp); -free (filename); current->scale =1.0 ; current->offset =0 ; current->name = strndup(ent->d_name,
--
1.6.0.2
PATCH 3/6 IIO: Documentation: iio_utils: style consistency fix
In reply to [email protected]From: Michael Hennerich <[email protected]>
No functional changes
--- drivers/staging/iio/Documentation/iio_utils.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/iio/Documentation/iio_utils.h +1 -1
@@ -374,7 +374,7 @@ inline int build_channel_array(const char *device_dir, } }/* reorder so that the array is in index order*/ - current =malloc (sizeof (**ci_array)**counter); + current =malloc (sizeof (**ci_array)*(*counter));if (current ==NULL ) { ret = -ENOMEM ; goto error_cleanup_array;
--
1.6.0.2
PATCH 4/6 IIO: Documentation: iio_utils: Prevent buffer overflow
In reply to [email protected]From: Michael Hennerich <[email protected]>
The first part of build_channel_array()identifies the number of enabled channels. Further down this count is used to allocate the ci_array. The next section parses the scan_elements directory again, and fills ci_array regardless if the channel is enabled or not. So if less than available channels are enabled ci_array memory is overflowed.
This fix makes sure that we allocate enough memory. But the whole approach looks a bit cumbersome to me. Why not allocate memory for MAX_CHANNLES, less say 64 (I never seen a part with more than that channels). And skip the first part entirely.
--- drivers/staging/iio/Documentation/iio_utils.h | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/staging/iio/Documentation/iio_utils.h +3 -1
@@ -290,15 +290,17 @@ inline int build_channel_array(const char *device_dir,fscanf (sysfsfp,"%u" , &ret);if (ret ==1 ) (*counter)++; + count++;fclose (sysfsfp);free (filename); } - *ci_array =malloc (sizeof (**ci_array)*(*counter)); + *ci_array =malloc (sizeof (**ci_array)*count);if (*ci_array ==NULL ) { ret = -ENOMEM ; goto error_close_dir; }seekdir (dp,0 ); + count =0 ;while (ent =readdir (dp), ent !=NULL ) {if (strcmp (ent->d_name +strlen (ent->d_name) -strlen ("_en" ),"_en" ) ==0 ) {
--
1.6.0.2
PATCH 5/6 IIO: Documentation: iio_utils: fix mask generation
In reply to [email protected]From: Michael Hennerich <[email protected]>
Variable sizeint is used uninitialized. Remove sizeint completely and use bits_used instead.
--- drivers/staging/iio/Documentation/iio_utils.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/Documentation/iio_utils.h +2 -2
@@ -113,7 +113,7 @@ inline int iioutils_get_type(unsigned *is_signed,DIR *dp;char *scan_el_dir, *builtname, *builtname_generic, *filename =0 ;char signchar; -unsigned sizeint, padint; +unsigned padint;const struct dirent *ent; ret =asprintf (&scan_el_dir,FORMAT_SCAN_ELEMENTS_DIR , device_dir);
@@ -159,7 +159,7 @@ inline int iioutils_get_type(unsigned *is_signed,fscanf (sysfsfp,"%c%u/%u" , &signchar, bits_used, &padint); *bytes = padint /8 ; -if (sizeint ==64 ) +if (*bits_used ==64 ) *mask = ~0 ;else *mask = (1 << *bits_used) -1 ;
--
1.6.0.2
Quoted 1 line · On Thu, Feb 24, 2011 at 04:34:50PM +0100, [email protected] wrote:
From: Michael Hennerich <[email protected]>
I only received 5 patches here, not six, missing the 6/6 patch. Did it get lost somewhere?
thanks,
greg k-h
Greg KH wrote on 2011-02-24:
Quoted 10 lines
Quoted 1 line · On Thu, Feb 24, 2011 at 04:34:50PM +0100, [email protected] wrote:
From: Michael Hennerich <[email protected]>
I only received 5 patches here, not six, missing the 6/6 patch. Did it get lost somewhere?
thanks,
greg k-h
No - I temporarily restrained it - Sorry I shouldn't made it part of the se= quence.
[PATCH 6/6] IIO: Documentation: iio_utils: fix channel array generation.
Was not yet Acked-by Jonathan and I got indication that he likes to test it=
and or
try to push it's alternative implementation.
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Gesch= aeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret=
Seif
Quoted 10 lines · Michael
Greg KH wrote on 2011-02-24:
Quoted 9 lines
Quoted 1 line · On Thu, Feb 24, 2011 at 04:34:50PM +0100, [email protected] wrote:
From: Michael Hennerich <[email protected]>
I only received 5 patches here, not six, missing the 6/6 patch. Did it get lost somewhere?
thanks,
Quoted 7 lines
Quoted 1 line
greg k-h
No - I temporarily restrained it - Sorry I shouldn't made it part of the sequence. [PATCH 6/6] IIO: Documentation:
iio_utils: fix channel array generation.Was not yet Acked-by Jonathan and I got indication that he likes to test it and or try to push it's alternative implementation.
Ok, just worried I missed a patch somewhere, thanks for the response.
greg k-h