1
Vote

Memory allocation problem in PhoneBase class

description

Hi,
 
You've a problem in the PhoneBase Class :
In the constructor, the current code is : m_data = new byte[Math.Min(nSize, MinimumSize)];
and I think it should be : m_data = new byte[Math.Max(nSize, MinimumSize)];
(replace min by max)
 
Look at the following code :
        dc = new DeviceCapabilities(1024);
        dc.Store();
        int ret = NativeMethods.lineGetDevCaps(m_hLineApp, deviceID, NegotiateVersion(deviceID), 0, dc.Data);
        dc.Load();
        if ( (ErrorCode)ret == ErrorCode.StructureTooSmall )
        {
            dc = new DeviceCapabilities(dc.NeededSize);
            ret = NativeMethods.lineGetDevCaps(m_hLineApp, deviceID, NegotiateVersion(deviceID), 0, dc.Data);
            dc.Load();
        }
        return (ErrorCode)ret;
 
On the line : dc = new DeviceCapabilities(dc.NeededSize);
If dc.NeededSize > 1024, then the DeviceCapabilities size will be only 1024 because that's the MinimumSize !!!!
Then the memory can be accessed (the code works) but you'll have later memory corruption problem.
 
Congratulation for publishing the code, it helped me a lot. Too bad your api can't change the baud rate using lineDevSpecific.
 
Regards,
Vincent Le Toux

comments