device: Fix memory corruption, allocate enought memory for device_list_alloc_to_bufs

This commit is contained in:
Pali Rohár committed 2012-11-24 12:39:47 +01:00
1 parent 3e863759d3
commit def1d49ab4
1 file changed
+6 -4
+6 -4
View File
@@ -158,6 +158,8 @@ char * hwrevs_alloc_to_string(const int16_t * hwrevs) {
} }
#define MAX_HWREVS 29
char ** device_list_alloc_to_bufs(const struct device_list * device_list) { char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
int count = 0; int count = 0;
@@ -183,9 +185,9 @@ char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
if ( device_first->hwrevs[i] >= 0 && device_first->hwrevs[i] <= 9999 ) if ( device_first->hwrevs[i] >= 0 && device_first->hwrevs[i] <= 9999 )
++local; ++local;
size += 1+16+local*8; size += (1+16+(MAX_HWREVS+1)*8)*(local/MAX_HWREVS+1);
count += local/30; count += local/MAX_HWREVS;
if ( local%30 != 0 || local == 0 ) if ( local%MAX_HWREVS != 0 || local == 0 )
++count; ++count;
device_first = device_first->next; device_first = device_first->next;
@@ -221,7 +223,7 @@ char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
k = 0; k = 0;
for ( k = 0; k < 30; ++k ) { for ( k = 0; k < MAX_HWREVS; ++k ) {
if ( device_first->hwrevs[i+1] == -1 ) if ( device_first->hwrevs[i+1] == -1 )
break; break;