System device enumeration and DevicePath

Hello,

Does anyone have any idea what is the maximum length of DevicePath
string for video capture devices returned by class enumerator:

VARIANT Value;
VariantInit(&Value);
pPropBag->Read(L"DevicePath", &Value, 0);

Returned strings can look like this for USB video capture devices:
//
L"\\?\usb#vid_058f&pid_3863&mi_00#7&25bdaaef&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"

I know that BSTR can be ~32K, but what is the practical limitation of
the driver/system?

Regards,
Igor

There is no documented limitation for the length of the string

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Igor Levicki
Sent: Sunday, March 29, 2015 11:09 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] System device enumeration and DevicePath

Hello,

Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:

VARIANT Value;
VariantInit(&Value);
pPropBag->Read(L"DevicePath", &Value, 0);

Returned strings can look like this for USB video capture devices:
// L"\\?\usb#vid_058f&pid_3863&mi_00#7&25bdaaef&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global<file:>"

I know that BSTR can be ~32K, but what is the practical limitation of the driver/system?

Regards,
Igor


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</file:>

Thank you Doron.

One more question – I have seen DirectShow drivers for certain devices
return the same string in DevicePath, FriendlyName, and Description
(that is, device path is not set to USB device symbolic link but to
device name). I have also seen another driver returning same
FriendlyName for multiple devices of the same kind. Is that kind of
behavior allowed?

Regards,
Igor

On 2015-03-29 20:25, Doron Holan wrote:

There is no documented limitation for the length of the string

*From:*xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] *On Behalf Of *Igor Levicki
*Sent:* Sunday, March 29, 2015 11:09 AM
*To:* Windows System Software Devs Interest List
*Subject:* [ntdev] System device enumeration and DevicePath

Hello,

Does anyone have any idea what is the maximum length of DevicePath
string for video capture devices returned by class enumerator:

VARIANT Value;
VariantInit(&Value);
pPropBag->Read(L"DevicePath", &Value, 0);

Returned strings can look like this for USB video capture devices:
//
L"\\?\usb#vid_058f&pid_3863&mi_00#7&25bdaaef&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global
<file:>"
>
> I know that BSTR can be ~32K, but what is the practical limitation of
> the driver/system?
>
> Regards,
> Igor
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</http:></file:>

Yes , these are optional properties

d

Bent from my phone


From: Igor Levickimailto:xxxxx
Sent: ?3/?29/?2015 1:30 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] System device enumeration and DevicePath

Thank you Doron.

One more question – I have seen DirectShow drivers for certain devices
return the same string in DevicePath, FriendlyName, and Description
(that is, device path is not set to USB device symbolic link but to
device name). I have also seen another driver returning same
FriendlyName for multiple devices of the same kind. Is that kind of
behavior allowed?

Regards,
Igor

On 2015-03-29 20:25, Doron Holan wrote:
>
> There is no documented limitation for the length of the string
>
> *From:*xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] *On Behalf Of *Igor Levicki
> Sent: Sunday, March 29, 2015 11:09 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] System device enumeration and DevicePath
>
> Hello,
>
> Does anyone have any idea what is the maximum length of DevicePath
> string for video capture devices returned by class enumerator:
>
> VARIANT Value;
> VariantInit(&Value);
> pPropBag->Read(L"DevicePath", &Value, 0);
>
> Returned strings can look like this for USB video capture devices:
> //
> L"\\?\usb#vid_058f&pid_3863&mi_00#7&25bdaaef&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global
> <file:>"
>
> I know that BSTR can be ~32K, but what is the practical limitation of
> the driver/system?
>
> Regards,
> Igor
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</http:></file:></mailto:xxxxx></mailto:xxxxx>

On Mar 29, 2015, at 11:09 AM, Igor Levicki > wrote:

Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:

Why on earth would you care? If you need to keep a copy, just use a CString.

Tim Roberts, xxxxx@probo.commailto:xxxxx
Providenza & Boekelheide, Inc.</mailto:xxxxx>

Because I am writing code in C? And because i wanted to avoid dynamic allocations?

Sent from my iPhone

On 30.03.2015., at 07.51, Tim Roberts wrote:
>
>> On Mar 29, 2015, at 11:09 AM, Igor Levicki wrote:
>>
>> Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:
>
> Why on earth would you care? If you need to keep a copy, just use a CString.
> —
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

You can’t hard code the string lengths, it has to be dynamic unless you want to give yourself bugs in the future

d

Bent from my phone


From: Igor Levickimailto:xxxxx
Sent: ?3/?29/?2015 11:33 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] System device enumeration and DevicePath

Because I am writing code in C? And because i wanted to avoid dynamic allocations?

Sent from my iPhone

On 30.03.2015., at 07.51, Tim Roberts > wrote:

On Mar 29, 2015, at 11:09 AM, Igor Levicki > wrote:

Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:

Why on earth would you care? If you need to keep a copy, just use a CString.
?
Tim Roberts, xxxxx@probo.commailto:xxxxx
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

That is why I asked whether there is a system limit so I know whether I have to allocate dynamically or not.

Sent from my iPhone

On 30.03.2015., at 09.17, Doron Holan wrote:
>
> You can’t hard code the string lengths, it has to be dynamic unless you want to give yourself bugs in the future
>
> d
>
> Bent from my phone
> From: Igor Levicki
> Sent: ‎3/‎29/‎2015 11:33 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] System device enumeration and DevicePath
>
> Because I am writing code in C? And because i wanted to avoid dynamic allocations?
>
> Sent from my iPhone
>
> On 30.03.2015., at 07.51, Tim Roberts wrote:
>
>>> On Mar 29, 2015, at 11:09 AM, Igor Levicki wrote:
>>>
>>> Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:
>>
>> Why on earth would you care? If you need to keep a copy, just use a CString.
>> —
>> Tim Roberts, xxxxx@probo.com
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Igor Levicki wrote:

Because I am writing code in C? And because i wanted to avoid dynamic
allocations?

Neither one of those things are compatible with maximizing programmer
productivity. In 21st Century programming, we don’t worry about dynamic
allocations.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Please, please do the dynamic allocations. Enough software in the world have buffer overrun bugs.

Even in C what you do with the strings is to write a StringClone() and StringFree() functions, not to say StringPrintfAlloc() and StringCatAlloc().

Doing otherwise is just to impose a pain on yourself, a potential for security issues for no value.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
“Igor Levicki” wrote in message news:xxxxx@ntdev…
Because I am writing code in C? And because i wanted to avoid dynamic allocations?

Sent from my iPhone

On 30.03.2015., at 07.51, Tim Roberts wrote:

On Mar 29, 2015, at 11:09 AM, Igor Levicki wrote:

Does anyone have any idea what is the maximum length of DevicePath string for video capture devices returned by class enumerator:

Why on earth would you care? If you need to keep a copy, just use a CString.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hello Maxim,

I already replied to Tim personally so as not to clutter the list, but
now I have to respond with some clarifications since many people seem to
have misunderstood the purpose of my question.

  1. More often than not programmers cannot choose on which platform their
    product will be used.
  2. MISRA rules do not agree with you when it comes to dynamic allocations.
  3. When you have 256MB of memory you should worry about dynamic
    allocations, especially if you are writing a Windows service which has
    to run for weeks or even months without reboot.
  4. When you know that any exception thrown by your service (for example
    by double free() or by accessing free’d memory) will reboot the platform
    (and that behavior is out of your control), you look for ways to
    minimize the risks.
  5. In this case worrying about buffer overruns is pointless when the
    system is running XP SP2 and both hardware and software is strictly
    controlled.

I hope the above explains why I was asking such a simple question. I do
not generally avoid using dynamic memory allocations, but for this
specific need I was considering it. I gave up once Doron told me there
is no limit imposed by system driver architecture.

Regards,
Igor Levicki
On 2015-03-30 20:47, Maxim S. Shatskih wrote:

Please, please do the dynamic allocations. Enough software in the
world have buffer overrun bugs.
Even in C what you do with the strings is to write a StringClone()
and StringFree() functions, not to say StringPrintfAlloc() and
StringCatAlloc().
Doing otherwise is just to impose a pain on yourself, a potential
for security issues for no value.

Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com mailto:xxxxx
> http://www.storagecraft.com
>
> “Igor Levicki” > mailto:xxxxx> wrote in message news:xxxxx@ntdev…
> Because I am writing code in C? And because i wanted to avoid
> dynamic allocations?
>
> Sent from my iPhone
>
> On 30.03.2015., at 07.51, Tim Roberts > mailto:xxxxx> wrote:
>
>> On Mar 29, 2015, at 11:09 AM, Igor Levicki
>> > wrote:
>>>
>>> Does anyone have any idea what is the maximum length of
>>> DevicePath string for video capture devices returned by class
>>> enumerator:
>>
>> Why on earth would you care? If you need to keep a copy, just
>> use a CString.
>> —
>> Tim Roberts, xxxxx@probo.com mailto:xxxxx
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

“3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.”

Dynamic allocations mean you use less memory than finding out the maximum length of the length of the string.

char DeviceName[MAX_DEVICEPATH_LEN]

vs.

DeviceName = ExAllocatePoolWithTag ( )

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Igor Levicki
Sent: Monday, March 30, 2015 12:07 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System device enumeration and DevicePath

Hello Maxim,

I already replied to Tim personally so as not to clutter the list, but now I have to respond with some clarifications since many people seem to have misunderstood the purpose of my question.

  1. More often than not programmers cannot choose on which platform their product will be used.
  2. MISRA rules do not agree with you when it comes to dynamic allocations.
  3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.
  4. When you know that any exception thrown by your service (for example by double free() or by accessing free’d memory) will reboot the platform (and that behavior is out of your control), you look for ways to minimize the risks.
  5. In this case worrying about buffer overruns is pointless when the system is running XP SP2 and both hardware and software is strictly controlled.

I hope the above explains why I was asking such a simple question. I do not generally avoid using dynamic memory allocations, but for this specific need I was considering it. I gave up once Doron told me there is no limit imposed by system driver architecture.

Regards,
Igor Levicki
On 2015-03-30 20:47, Maxim S. Shatskih wrote:

Please, please do the dynamic allocations. Enough software in the
world have buffer overrun bugs.
Even in C what you do with the strings is to write a StringClone()
and StringFree() functions, not to say StringPrintfAlloc() and
StringCatAlloc().
Doing otherwise is just to impose a pain on yourself, a potential
for security issues for no value.

Maxim S. Shatskih
Microsoft MVP on File System And Storage xxxxx@storagecraft.com
mailto:xxxxx http://www.storagecraft.com
>
> “Igor Levicki” > mailto:xxxxx> wrote in message news:xxxxx@ntdev…
> Because I am writing code in C? And because i wanted to avoid
> dynamic allocations?
>
> Sent from my iPhone
>
> On 30.03.2015., at 07.51, Tim Roberts > mailto:xxxxx> wrote:
>
>> On Mar 29, 2015, at 11:09 AM, Igor Levicki
>> > wrote:
>>>
>>> Does anyone have any idea what is the maximum length of
>>> DevicePath string for video capture devices returned by class
>>> enumerator:
>>
>> Why on earth would you care? If you need to keep a copy, just
>> use a CString.
>> —
>> Tim Roberts, xxxxx@probo.com mailto:xxxxx
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at:
>> http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Just one minor correction – if char DeviceName is inside of a block
then it is an automatic variable (stack allocated), not static allocation.

When I asked whether there is a string length limitation I was looking
specifically for maximum DevicePath length returned by this class
enumerator:

hr =
pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);

In my opinion there is no point in allowing video capture (or any other
device) drivers to waste up to 64KB of memory per device attached. Or is
there? If there is then I apologize for not seeing it. Maybe allowing
symbolic links for devices with 32,767 Unicode characters is some sort
of “future proof” design?

Also suggestion to “just use CString” is bad because BSTR returned by
reading the property bag can contain embedded null characters so you
could theoretically truncate the string and break your code.

Regards,
Igor

On 2015-03-30 21:11, Edwards, Jonathan wrote:

“3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.”

Dynamic allocations mean you use less memory than finding out the maximum length of the length of the string.

char DeviceName[MAX_DEVICEPATH_LEN]

vs.

DeviceName = ExAllocatePoolWithTag ( )

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Igor Levicki
Sent: Monday, March 30, 2015 12:07 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System device enumeration and DevicePath

Hello Maxim,

I already replied to Tim personally so as not to clutter the list, but now I have to respond with some clarifications since many people seem to have misunderstood the purpose of my question.

  1. More often than not programmers cannot choose on which platform their product will be used.
  2. MISRA rules do not agree with you when it comes to dynamic allocations.
  3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.
  4. When you know that any exception thrown by your service (for example by double free() or by accessing free’d memory) will reboot the platform (and that behavior is out of your control), you look for ways to minimize the risks.
  5. In this case worrying about buffer overruns is pointless when the system is running XP SP2 and both hardware and software is strictly controlled.

I hope the above explains why I was asking such a simple question. I do not generally avoid using dynamic memory allocations, but for this specific need I was considering it. I gave up once Doron told me there is no limit imposed by system driver architecture.

Regards,
Igor Levicki
On 2015-03-30 20:47, Maxim S. Shatskih wrote:
> Please, please do the dynamic allocations. Enough software in the
> world have buffer overrun bugs.
> Even in C what you do with the strings is to write a StringClone()
> and StringFree() functions, not to say StringPrintfAlloc() and
> StringCatAlloc().
> Doing otherwise is just to impose a pain on yourself, a potential
> for security issues for no value.
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage xxxxx@storagecraft.com
> mailto:xxxxx http://www.storagecraft.com
>>
>> “Igor Levicki” >> mailto:xxxxx> wrote in message news:xxxxx@ntdev…
>> Because I am writing code in C? And because i wanted to avoid
>> dynamic allocations?
>>
>> Sent from my iPhone
>>
>> On 30.03.2015., at 07.51, Tim Roberts >> mailto:xxxxx> wrote:
>>
>>> On Mar 29, 2015, at 11:09 AM, Igor Levicki
>>> > wrote:
>>>> Does anyone have any idea what is the maximum length of
>>>> DevicePath string for video capture devices returned by class
>>>> enumerator:
>>> Why on earth would you care? If you need to keep a copy, just
>>> use a CString.
>>> —
>>> Tim Roberts, xxxxx@probo.com mailto:xxxxx
>>> Providenza & Boekelheide, Inc.
>>>
>>>
>>> —
>>> NTDEV is sponsored by OSR
>>>
>>> Visit the list at:
>>> http://www.osronline.com/showlists.cfm?list=ntdev
>>>
>>> OSR is HIRING!! See http://www.osr.com/careers
>>>
>>> For our schedule of WDF, WDM, debugging and other seminars visit:
>>> http://www.osr.com/seminars
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Igor Levicki wrote:

In my opinion there is no point in allowing video capture (or any other
device) drivers to waste up to 64KB of memory per device attached. Or is
there?

Well, they don’t. The property bag stores whatever is necessary to hold
the value. The VARIANT structure tells you how much memory you need to
hold a copy.

If there is then I apologize for not seeing it. Maybe allowing
symbolic links for devices with 32,767 Unicode characters is some sort
of “future proof” design?

Yes. When the API was designed, the “device interface” concept had not
been invented yet. That added a lengthy GUID to each name. It’s not
impossible to envision other enhancements that might lengthen them even
more.

Part of this was a “lesson learned”. In the beginning, everyone used
MAX_PATH for their buffers, as a leftover from DOS. That was defined at
260, and it quickly became evident that it was not enough. 64k is
intended to be “infinitely large”.

Also suggestion to “just use CString” is bad because BSTR returned by
reading the property bag can contain embedded null characters so you
could theoretically truncate the string and break your code.

A BSTR is allowed to contain null characters, but the DevicePath
property cannot. The device path name is fed directly to CreateFile,
which does not allow embedded nulls.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

"-- if char DeviceName is inside of a block then it is an automatic variable (stack allocated), not static allocation.

It’s still a good idea to use dynamic allocation instead of large local variables. The kernel stack isn’t very big.

And if you’re only using the string within a function, who cares how big it is. Allocating a big buffer then freeing it a few nanoseconds later isn’t going to stress memory.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Igor Levicki
Sent: Monday, March 30, 2015 1:39 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System device enumeration and DevicePath

Just one minor correction – if char DeviceName is inside of a block then it is an automatic variable (stack allocated), not static allocation.

When I asked whether there is a string length limitation I was looking specifically for maximum DevicePath length returned by this class
enumerator:

hr =
pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum,
pDevEnum->0);

In my opinion there is no point in allowing video capture (or any other
device) drivers to waste up to 64KB of memory per device attached. Or is there? If there is then I apologize for not seeing it. Maybe allowing symbolic links for devices with 32,767 Unicode characters is some sort of “future proof” design?

Also suggestion to “just use CString” is bad because BSTR returned by reading the property bag can contain embedded null characters so you could theoretically truncate the string and break your code.

Regards,
Igor

On 2015-03-30 21:11, Edwards, Jonathan wrote:

“3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.”

Dynamic allocations mean you use less memory than finding out the maximum length of the length of the string.

char DeviceName[MAX_DEVICEPATH_LEN]

vs.

DeviceName = ExAllocatePoolWithTag ( )

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Igor Levicki
Sent: Monday, March 30, 2015 12:07 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System device enumeration and DevicePath

Hello Maxim,

I already replied to Tim personally so as not to clutter the list, but now I have to respond with some clarifications since many people seem to have misunderstood the purpose of my question.

  1. More often than not programmers cannot choose on which platform their product will be used.
  2. MISRA rules do not agree with you when it comes to dynamic allocations.
  3. When you have 256MB of memory you should worry about dynamic allocations, especially if you are writing a Windows service which has to run for weeks or even months without reboot.
  4. When you know that any exception thrown by your service (for example by double free() or by accessing free’d memory) will reboot the platform (and that behavior is out of your control), you look for ways to minimize the risks.
  5. In this case worrying about buffer overruns is pointless when the system is running XP SP2 and both hardware and software is strictly controlled.

I hope the above explains why I was asking such a simple question. I do not generally avoid using dynamic memory allocations, but for this specific need I was considering it. I gave up once Doron told me there is no limit imposed by system driver architecture.

Regards,
Igor Levicki
On 2015-03-30 20:47, Maxim S. Shatskih wrote:
> Please, please do the dynamic allocations. Enough software in
> the world have buffer overrun bugs.
> Even in C what you do with the strings is to write a
> StringClone() and StringFree() functions, not to say
> StringPrintfAlloc() and StringCatAlloc().
> Doing otherwise is just to impose a pain on yourself, a
> potential for security issues for no value.
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage xxxxx@storagecraft.com
> mailto:xxxxx http://www.storagecraft.com
>>
>> “Igor Levicki” >> mailto:xxxxx> wrote in message news:xxxxx@ntdev…
>> Because I am writing code in C? And because i wanted to avoid
>> dynamic allocations?
>>
>> Sent from my iPhone
>>
>> On 30.03.2015., at 07.51, Tim Roberts >> mailto:xxxxx> wrote:
>>
>>> On Mar 29, 2015, at 11:09 AM, Igor Levicki
>>> > wrote:
>>>> Does anyone have any idea what is the maximum length of
>>>> DevicePath string for video capture devices returned by class
>>>> enumerator:
>>> Why on earth would you care? If you need to keep a copy, just
>>> use a CString.
>>> —
>>> Tim Roberts, xxxxx@probo.com mailto:xxxxx
>>> Providenza & Boekelheide, Inc.
>>>
>>>
>>> —
>>> NTDEV is sponsored by OSR
>>>
>>> Visit the list at:
>>> http://www.osronline.com/showlists.cfm?list=ntdev
>>>
>>> OSR is HIRING!! See http://www.osr.com/careers
>>>
>>> For our schedule of WDF, WDM, debugging and other seminars visit:
>>> http://www.osr.com/seminars
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

>64k is intended to be “infinitely large”.

If we really need 64K to uniquely identify a device while at the same time DevicePath, FriendlyName and Description are optional and free-formed, then to me it looks we are doing something wrong.

A BSTR is allowed to contain null characters, but the DevicePath property cannot.
The device path name is fed directly to CreateFile, which does not allow embedded nulls.

Now that is a usefull bit of info – which is not documented on MSDN as usual, and their example code for device enumeration tells you to use SysStringByteLength() because of possible embedded nulls.

On 30-Mar-2015 22:06, Igor Levicki wrote:

  1. MISRA rules do not agree with you when it comes to dynamic allocations.

Ah, MISRA rules. Been there :frowning: They have few good points,
but otherwise IMHO they are targeted to low-skill outsourced
workforce, like what India was 15 years ago, and toolkits now obsolete.
Not all these rules are mandatory, selection of applicable rules
is up to the project managers.
Try to fight back and challenge unreasonable requirements.
It makes no sense to forbid dynamic allocation in Windows environment,
which does allocations itself (various kernel objects…)

  1. When you have 256MB of memory you should worry about dynamic
    allocations, especially if you are writing a Windows service which has
    to run for weeks or even months without reboot.

Just be careful and free what you allocated.
There are various tactics to help avoiding leaks,
every embedded developer knows some.

Good luck…
– pa

> 1. More often than not programmers cannot choose on which platform their

product will be used.

This code will be used on Windows, and not on some other platform, isn’t this obvious?

  1. MISRA rules do not agree with you when it comes to dynamic allocations.

MISRA rules - after a quick Google search - prohibit any sane C coding :slight_smile: Not only malloc() is prohibited, but also offsetof().

Neither Windows nor Linux is definitely not compatible with such moronic rules. Only some tiny OS-less embedded code with hardcoded table sizes (design of 1970ies like of RSX-11M), string sizes (hello buffer overruns!) etc.

And yes, DirectShow (which is what you’re working on) is not compatible with such moronic rules too.

Another guy (his name is Mr. Bill Gatliff) here is agree with me on “moronic”:

http://www.embedded.com/design/prototyping-and-development/4007569/The-yin-and-yang-of-dynamic-allocation

No wonder that, after such moronic rules were developed, we have stack overflow bug in Toyota’s ECU which causes the engine to sometimes do full throttle without the human pushing a gas pedal.

Surely, if you ban dynamic allocations, people WILL allocate stuff on stack, to overflow it soon.

I really cannot understand why pull this nightmarish coding style of 1970ies (or assembler coding style of ZX-Spectrum of 1990ies) to modern OSes.

  1. When you have 256MB of memory you should worry about dynamic
    allocations,

256MB is not enough to allocate the DirectShow device name? amazing :slight_smile:

256MB is I think the RAM size of iPhone 1, which could run lots of smart apps.

especially if you are writing a Windows service which has
to run for weeks or even months without reboot.

Nothing fancy. Windows or Linux kernel, with lots of custom drivers, is surely capable of this. And yes, both use dynamic allocations a lot.

Test your stuff with a memory leak detector. Use AppVerifier, or write your own (like MFC does).

  1. When you know that any exception thrown by your service (for example
    by double free() or by accessing free’d memory)

Eliminate all this stuff by testing.

Or well, use C++ and wrap all allocations to classes. This will even increase the stability, and is a Best Way To Defeat The Buffer Overruns since at least 1992.

(and that behavior is out of your control), you look for ways to
minimize the risks.

Minimizing the risks by hardcoding the sizes???

Don’t you understand that you (together with the authors of the moronic rule set mentioned above) maximize the risks instead?

It is by far easier to miss something in the size calculation, then to free() a wrong pointer. Much easier.

  1. In this case worrying about buffer overruns is pointless when the
    system is running XP SP2 and both hardware and software is strictly
    controlled.

Oh my God… it is your code which will do the buffer overrun, not XP SP2s :slight_smile:

Yes, your strictly controlled code, on your strictly controlled hardware.

It will do the buffer overrun immediately after the static array you use for some string will have size 1 less since you’ve forgotten to count the terminating zero.

BTW - why SP2? Why not SP3? Another moronity?

I hope the above explains why I was asking such a simple question.

Oh yes. You’re pushing the very, very doubtful rules from the world of 64K embedded systems (I doubt that, for instance, MISRA-compatible TCP/IP stack ever existed) to modern (well, XP is not, but still more or less modern) mature OS with 256MB of memory.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

> It makes no sense to forbid dynamic allocation in Windows environment,

which does allocations itself (various kernel objects…)

I think Windows does millions of such calls per second.

Adding 1 to 1000000 is neglectable.

And yes, even on 64M machines with NT4, people were OK with dynamic allocations.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

> Just one minor correction – if char DeviceName is inside of a block

then it is an automatic variable (stack allocated)

Oh yes, let’s overflow the stack :slight_smile:

Stack-allocated variables are evil, at least in most OS kernels where you have very limited stack space. I doubt that embedded world have lesser strict stack size limit then Windows kernel.

The world is exactly vice versa to what MISRA suggests :slight_smile:

hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);

Don’t you understand that this line of code will do probably like 100 alloc/free calls in it?

In my opinion there is no point in allowing video capture (or any other
device) drivers to waste up to 64KB of memory per device attached.

Correct. That’s why dynamic allocations are here.

It is absolutely amazing (I would say it is the monthly greatest thread on this forum) to avoid dynamic allocations working with DirectShow on Windows, which are surely written to a paradigm perpendicular to what MISRA suggests?

symbolic links for devices with 32,767 Unicode characters is some sort
of “future proof” design?

Modern (i.e. 1990-up) OSes just avoid any such limits. The limit is “up to memory permits” or “up to datatype size permits” (as for strings).

The MAX_PATH limit in Windows is MS-DOS legacy from 1980ies, and native Windows layers are free from it.

Also suggestion to “just use CString” is bad because BSTR returned by
reading the property bag can contain embedded null characters

DirectShow device name (which is in turn PnP devinterface name) contains embedded NULLs?

could theoretically truncate the string and break your code.

At least the code will not crash miserably, as what MISRA-compliant code will do :slight_smile:

The code will just fail on device open.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com