Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is VALENT(A/W)::ve_valuename non-const #1778

Open
JaiganeshKumaran opened this issue Dec 24, 2023 · 4 comments
Open

Why is VALENT(A/W)::ve_valuename non-const #1778

JaiganeshKumaran opened this issue Dec 24, 2023 · 4 comments

Comments

@JaiganeshKumaran
Copy link

I know that VALENT(A/W)::ve_valuename is non-const in the SDK headers, but it should really not be that way.

@riverar
Copy link
Collaborator

riverar commented Dec 25, 2023

Interestingly, Windows NT 3.5 (when RegQueryMultipleValues was introduced) describes this as

typedef struct value_ent {  /* val */  
    LPCTSTR  ve_valuename; 
    DWORD    ve_valuelen; 
    DWORD    ve_valueptr; 
    DWORD    ve_type; 
} RECT; 

(The RECT typedef is a typo in the original docs.)

Now to find when that changed...

@riverar
Copy link
Collaborator

riverar commented Dec 25, 2023

The NT 3.5 docs don't appear to have ever been truly in sync with the original header definition from NT 3.5:

// winreg.h
// ...
typedef struct value_entA {
    LPSTR   ve_valuename;
    DWORD ve_valuelen;
    DWORD ve_valueptr;
    DWORD ve_type;
}VALENTA, FAR *PVALENTA;
typedef struct value_entW {
    LPWSTR  ve_valuename;
    DWORD ve_valuelen;
    DWORD ve_valueptr;
    DWORD ve_type;
}VALENTW, FAR *PVALENTW;
#ifdef UNICODE
typedef VALENTW VALENT;
typedef PVALENTW PVALENT;
#else
typedef VALENTA VALENT;
typedef PVALENTA PVALENT;
#endif // UNICODE

NT 4.0 docs correct this mishap though:

typedef struct value_ent {
    LPTSTR   ve_valuename;
    DWORD ve_valuelen;
    DWORD ve_valueptr;
    DWORD ve_type;
}VALENT;

@riverar
Copy link
Collaborator

riverar commented Dec 25, 2023

Tried variations incl. remote registry servers, ANSI/UTF-16, etc. and could not see any issues. Looks to simply be an oversight, but I'm not sure it's appropriate for metadata to assert const here as it could change at any time.

@JaiganeshKumaran
Copy link
Author

JaiganeshKumaran commented Dec 26, 2023

The name of the value to be retrieved. Be sure to set this member before calling RegQueryMultipleValues.

This only implies that it is used as an in-parameter. You could maybe analyse the Windows codebase to ensure that it is always used only like that. Also, I speculate that lots of code simply const_cast's string literals to fill the structure and call RegQueryMultipleValues. Changing the behaviour will cause a lot of crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants