Procházet zdrojové kódy

[build] Fix signed/unsigned division in util/zbin.c

Commit b149a99 ([build] Round up SUBx deltas) introduced a
signed/unsigned issue that affects gPXE images built on 32-bit hosts.
The zbin fixup utility performed an unsigned division, which led to
.usb images with an incorrect number of sectors to load.

The issue snuck by on 64-bit hosts since uint32_t is promoted to long.
On 32-bit hosts it is promoted to unsigned long.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v0.9.8
Stefan Hajnoczi před 15 roky
rodič
revize
9b964dec36
1 změnil soubory, kde provedl 5 přidání a 4 odebrání
  1. 5
    4
      src/util/zbin.c

+ 5
- 4
src/util/zbin.c Zobrazit soubor

213
 				    size_t datasize ) {
213
 				    size_t datasize ) {
214
 	size_t offset = subtract->offset;
214
 	size_t offset = subtract->offset;
215
 	void *target;
215
 	void *target;
216
-	long delta;
216
+	signed long raw_delta;
217
+	signed long delta;
217
 	unsigned long old;
218
 	unsigned long old;
218
 	unsigned long new;
219
 	unsigned long new;
219
 
220
 
224
 	}
225
 	}
225
 
226
 
226
 	target = ( output->buf + offset );
227
 	target = ( output->buf + offset );
227
-	delta = ( ( align ( output->len, subtract->divisor ) -
228
-		    align ( input->len, subtract->divisor ) )
229
-		  / subtract->divisor );
228
+	raw_delta = ( align ( output->len, subtract->divisor ) -
229
+		      align ( input->len, subtract->divisor ) );
230
+	delta = ( raw_delta / ( ( signed long ) subtract->divisor ) );
230
 
231
 
231
 	switch ( datasize ) {
232
 	switch ( datasize ) {
232
 	case 1: {
233
 	case 1: {

Načítá se…
Zrušit
Uložit