-
Notifications
You must be signed in to change notification settings - Fork 11
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
Null termination of VERSIONINFO strings? #2
Comments
I'm doing some research on this issue: https://devblogs.microsoft.com/oldnewthing/20040130-00/?p=40813
https://stackoverflow.com/questions/45491778/why-do-mfc-rc-files-sometimes-have-a-manually-inserted-0-at-the-end
WCHAR* str;
int str_len;
str_len = LoadStringW(hInstance, ID_STRING, (LPWSTR) &str, 0); In this case it just stores the address of the original string resource into the str as mapped into process memory and no string copying happens. Obviously the -> Long story short, it looks like, indeed, we should NULL-terminate them |
https://devblogs.microsoft.com/oldnewthing/20061221-02/?p=28643 Hmmm... It looks like it already adds a NULL somehow? The length is
The only thing I don't understand is why in the blog post, the length seems to be in bytes, but here it is in characters. |
Would you look at that, Mr. Chen has an answer for this as well. Not surprised at all. https://devblogs.microsoft.com/oldnewthing/20061222-00/?p=28623
Uhh... So, that means my resource generator is bugged? |
Yep, the wrong number of bytes looks like a https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=binutils/resbin.c;hb=HEAD /* Convert a stringtable resource to binary. */
static rc_uint_type
res_to_bin_stringtable (windres_bfd *wrbfd, rc_uint_type off,
const rc_stringtable *st)
{
int i;
for (i = 0; i < 16; i++)
{
rc_uint_type slen, length;
unichar *s;
slen = (rc_uint_type) st->strings[i].length;
if (slen == 0xffffffff) slen = 0;
s = st->strings[i].string;
length = 2 + slen * 2;
if (wrbfd)
{
bfd_byte *hp;
rc_uint_type j;
hp = (bfd_byte *) reswr_alloc (length);
windres_put_16 (wrbfd, hp, slen);
for (j = 0; j < slen; j++)
windres_put_16 (wrbfd, hp + 2 + j * 2, s[j]);
set_windres_bfd_content (wrbfd, hp, off, length);
}
off += length;
}
return off;
} As we can see here The opposite direction is also wrong but it does have a length check: /* Convert a stringtable resource from binary. */
static rc_res_resource *
bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
{
rc_stringtable *st;
int i;
rc_res_resource *r;
st = (rc_stringtable *) res_alloc (sizeof (rc_stringtable));
for (i = 0; i < 16; i++)
{
unsigned int slen;
if (length < 2)
toosmall (_("stringtable string length"));
slen = windres_get_16 (wrbfd, data, 2);
st->strings[i].length = slen;
if (slen > 0)
{
unichar *s;
unsigned int j;
if (length < 2 + 2 * slen)
toosmall (_("stringtable string"));
s = (unichar *) res_alloc (slen * sizeof (unichar));
st->strings[i].string = s;
for (j = 0; j < slen; j++)
s[j] = windres_get_16 (wrbfd, data + 2 + j * 2, 2);
}
data += 2 + 2 * slen;
length -= 2 + 2 * slen;
}
r = (rc_res_resource *) res_alloc (sizeof *r);
r->type = RES_TYPE_STRINGTABLE;
r->u.stringtable = st;
return r;
} |
Track issue mxre/winres#25
The text was updated successfully, but these errors were encountered: