Commit c717d8bf13d4c24372c4885eefa821ec76378d2b

Authored by balrog
1 parent 7241f532

Simplify guess_disk_lchs - should fix Windows stack corruption spotted by TeLeMa…

…n (patch by Tristan Gingold).


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3953 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 1 additions and 8 deletions
hw/ide.c
@@ -2474,22 +2474,17 @@ struct partition { @@ -2474,22 +2474,17 @@ struct partition {
2474 static int guess_disk_lchs(IDEState *s, 2474 static int guess_disk_lchs(IDEState *s,
2475 int *pcylinders, int *pheads, int *psectors) 2475 int *pcylinders, int *pheads, int *psectors)
2476 { 2476 {
2477 - uint8_t *buf; 2477 + uint8_t *buf = s->io_buffer;
2478 int ret, i, heads, sectors, cylinders; 2478 int ret, i, heads, sectors, cylinders;
2479 struct partition *p; 2479 struct partition *p;
2480 uint32_t nr_sects; 2480 uint32_t nr_sects;
2481 2481
2482 - buf = qemu_memalign(512, 512);  
2483 - if (buf == NULL)  
2484 - return -1;  
2485 ret = bdrv_read(s->bs, 0, buf, 1); 2482 ret = bdrv_read(s->bs, 0, buf, 1);
2486 if (ret < 0) { 2483 if (ret < 0) {
2487 - qemu_free(buf);  
2488 return -1; 2484 return -1;
2489 } 2485 }
2490 /* test msdos magic */ 2486 /* test msdos magic */
2491 if (buf[510] != 0x55 || buf[511] != 0xaa) { 2487 if (buf[510] != 0x55 || buf[511] != 0xaa) {
2492 - qemu_free(buf);  
2493 return -1; 2488 return -1;
2494 } 2489 }
2495 for(i = 0; i < 4; i++) { 2490 for(i = 0; i < 4; i++) {
@@ -2512,11 +2507,9 @@ static int guess_disk_lchs(IDEState *s, @@ -2512,11 +2507,9 @@ static int guess_disk_lchs(IDEState *s,
2512 printf("guessed geometry: LCHS=%d %d %d\n", 2507 printf("guessed geometry: LCHS=%d %d %d\n",
2513 cylinders, heads, sectors); 2508 cylinders, heads, sectors);
2514 #endif 2509 #endif
2515 - qemu_free(buf);  
2516 return 0; 2510 return 0;
2517 } 2511 }
2518 } 2512 }
2519 - qemu_free(buf);  
2520 return -1; 2513 return -1;
2521 } 2514 }
2522 2515