From fb98f7b7824bd394d64f56e6aa05436f8c1a7c6c Mon Sep 17 00:00:00 2001 From: Kai Tietz Date: Wed, 28 Nov 2012 15:53:37 +0000 Subject: [PATCH] * resbin.c (bin_to_res_version): Correct offset and length calculation of resource. (get_version_header): Apply alignement of 4 to len. --- binutils/ChangeLog | 6 ++++++ binutils/resbin.c | 14 +++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index a763235f142..46fda072079 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2012-11-27 Kai Tietz + + * resbin.c (bin_to_res_version): Correct offset + and length calculation of resource. + (get_version_header): Apply alignement of 4 to len. + 2012-11-16 H.J. Lu * readelf.c (process_dynamic_section): Correct DF_1_CONFALT. diff --git a/binutils/resbin.c b/binutils/resbin.c index b5dcd9b5f2c..548ff38a6c8 100644 --- a/binutils/resbin.c +++ b/binutils/resbin.c @@ -909,7 +909,7 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt if (length < 8) toosmall (key); - *len = windres_get_16 (wrbfd, data, 2); + *len = (windres_get_16 (wrbfd, data, 2) + 3) & ~3; *vallen = windres_get_16 (wrbfd, data + 2, 2); *type = windres_get_16 (wrbfd, data + 4, 2); @@ -1041,10 +1041,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt data += off; length -= off; - /* It's convenient to round verlen to a 4 byte alignment, - since we round the subvariables in the loop. */ - - verlen = (verlen + 3) &~ 3; + verlen -= off; vi->u.string.stringtables = NULL; ppvst = &vi->u.string.stringtables; @@ -1070,7 +1067,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt length -= off; verlen -= off; - stverlen = (stverlen + 3) &~ 3; + stverlen -= off; vst->strings = NULL; ppvs = &vst->strings; @@ -1088,14 +1085,12 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt get_version_header (wrbfd, data, length, (const char *) NULL, &vs->key, &sverlen, &vallen, &type, &off); - sverlen = (sverlen + 3) &~ 3; - data += off; length -= off; vs->value = get_unicode (wrbfd, data, length, &vslen); valoff = vslen * 2 + 2; - valoff = (valoff + 3) &~ 3; + valoff = (valoff + 3) & ~3; if (off + valoff != sverlen) fatal (_("unexpected version string length %ld != %ld + %ld"), @@ -1108,6 +1103,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt fatal (_("unexpected version string length %ld < %ld"), (long) verlen, (long) sverlen); stverlen -= sverlen; + verlen -= sverlen; vs->next = NULL; *ppvs = vs; -- 2.30.2