Chameleon

Issue 319: Possible bug in i386/libsaio/device_inject.c devprop_add_device()

Reported by Damir Mazar, Jan 25, 2013

i386/libsaio/device_inject.c  devprop_add_device()
There is a code:

-- start -----------------------
	if(!string->entries)
		if((string->entries = (struct 
DevPropDevice**)malloc(sizeof(device)))== NULL)
			return 0;
	
	string->entries[string->numentries++] = (struct 
DevPropDevice*)malloc(sizeof(device));
	string->entries[string->numentries-1] = device;
-- end -----------------------

and it looks like allocating string->entries is not correct. I 
think it should be something like this:

-- start -----------------------
    #define DEV_PROP_DEVICE_MAX_ENTRIES 64
	if(!string->entries)
		if((string->entries = (struct 
DevPropDevice**)malloc(DEV_PROP_DEVICE_MAX_ENTRIES * 
sizeof(device)))== NULL)
			return 0;
	
	string->entries[string->numentries++] = device;
-- end -----------------------

or some dynamic allocation/relocation of string->entries when new 
 device is added.

Do not know how to format this properly in this edit box, sorry.

Comment 1 by ErmaC , Jan 25, 2013

Thx for the finding dmazar.
Intresting.

ErmaC

Comment 2 by Evan Lojewski, Jan 26, 2013

Status: Accepted

Comment 3 by ErmaC , Jan 28, 2013

Hi dmazar.
I test your changes.
And probably need more correction because affect
(The only one I find) the code above in nvidia.c
============
	if (getValueForKey(kDcfg0, &value, &len, 
&bootInfo->chameleonConfig) && len == DCFG0_LEN * 2)
	{
		uint8_t new_dcfg0[DCFG0_LEN];

		if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0)
		{
			memcpy(default_dcfg_0, new_dcfg0, DCFG0_LEN);

			verbose("Using user supplied @0,display-cfg\n");
			printf("@0,display-cfg: 0x%02x, 0x%02x, 0x%02x, 
0x%02x\n",
				   default_dcfg_0[0], default_dcfg_0[1], default_dcfg_0[2], 
default_dcfg_0[3]);
		}
	}

	if (getValueForKey(kDcfg1, &value, &len, 
&bootInfo->chameleonConfig) && len == DCFG1_LEN * 2)
	{
		uint8_t new_dcfg1[DCFG1_LEN];

		if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0)
		{
			memcpy(default_dcfg_1, new_dcfg1, DCFG1_LEN);

			verbose("Using user supplied @1,display-cfg\n");
			printf("@1,display-cfg: 0x%02x, 0x%02x, 0x%02x, 
0x%02x\n",
				   default_dcfg_1[0], default_dcfg_1[1], default_dcfg_1[2], 
default_dcfg_1[3]);
		}
	}
============
the result:
if I "manually" set my display value in o.c.B.p
with
-------
<key>display_0</key>
<string>03010300</string>
<key>display_1</key>
<string>ffff0001</string>
-------
the result in IOREG are < 00 00 00 00 >
for both display.

ErmaC

Comment 4 by armel cadet-petit, Jan 29, 2013

hi guys, just look at my branch, i've already fixed it long time ago 
;-) :

http://forge.voodooprojects.org/p/chameleon/source/tree/HEAD/branches
/cparm/i386/libsaio/device_inject.c

Comment 5 by Damir Mazar, Jan 29, 2013

@ErmaC, I do not know if this is related, sorry.

@cparm, good, confirms that I'm not mad after all :)

Comment 6 by Cosmosis Jones, Feb 1, 2013

Status: Fixed

Created: 11 years 3 months ago by Damir Mazar

Updated: 11 years 2 months ago

Status: Fixed

Followed by: 4 persons

Labels:
Priority:Medium
Type:Defect