瀏覽代碼

[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 15 年之前
父節點
當前提交
9b964dec36
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5
    4
      src/util/zbin.c

+ 5
- 4
src/util/zbin.c 查看文件

@@ -213,7 +213,8 @@ static int process_zinfo_subtract ( struct input_file *input,
213 213
 				    size_t datasize ) {
214 214
 	size_t offset = subtract->offset;
215 215
 	void *target;
216
-	long delta;
216
+	signed long raw_delta;
217
+	signed long delta;
217 218
 	unsigned long old;
218 219
 	unsigned long new;
219 220
 
@@ -224,9 +225,9 @@ static int process_zinfo_subtract ( struct input_file *input,
224 225
 	}
225 226
 
226 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 232
 	switch ( datasize ) {
232 233
 	case 1: {

Loading…
取消
儲存