Simplify guess_disk_lchs - should fix Windows stack corruption spotted by TeLeMan (patch by Tristan Gingold).
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3953 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
		
							parent
							
								
									7241f532c3
								
							
						
					
					
						commit
						c717d8bf13
					
				
							
								
								
									
										9
									
								
								hw/ide.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								hw/ide.c
									
									
									
									
									
								
							@ -2474,22 +2474,17 @@ struct partition {
 | 
				
			|||||||
static int guess_disk_lchs(IDEState *s,
 | 
					static int guess_disk_lchs(IDEState *s,
 | 
				
			||||||
                           int *pcylinders, int *pheads, int *psectors)
 | 
					                           int *pcylinders, int *pheads, int *psectors)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t *buf;
 | 
					    uint8_t *buf = s->io_buffer;
 | 
				
			||||||
    int ret, i, heads, sectors, cylinders;
 | 
					    int ret, i, heads, sectors, cylinders;
 | 
				
			||||||
    struct partition *p;
 | 
					    struct partition *p;
 | 
				
			||||||
    uint32_t nr_sects;
 | 
					    uint32_t nr_sects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    buf = qemu_memalign(512, 512);
 | 
					 | 
				
			||||||
    if (buf == NULL)
 | 
					 | 
				
			||||||
        return -1;
 | 
					 | 
				
			||||||
    ret = bdrv_read(s->bs, 0, buf, 1);
 | 
					    ret = bdrv_read(s->bs, 0, buf, 1);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
        qemu_free(buf);
 | 
					 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* test msdos magic */
 | 
					    /* test msdos magic */
 | 
				
			||||||
    if (buf[510] != 0x55 || buf[511] != 0xaa) {
 | 
					    if (buf[510] != 0x55 || buf[511] != 0xaa) {
 | 
				
			||||||
        qemu_free(buf);
 | 
					 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    for(i = 0; i < 4; i++) {
 | 
					    for(i = 0; i < 4; i++) {
 | 
				
			||||||
@ -2512,11 +2507,9 @@ static int guess_disk_lchs(IDEState *s,
 | 
				
			|||||||
            printf("guessed geometry: LCHS=%d %d %d\n",
 | 
					            printf("guessed geometry: LCHS=%d %d %d\n",
 | 
				
			||||||
                   cylinders, heads, sectors);
 | 
					                   cylinders, heads, sectors);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
            qemu_free(buf);
 | 
					 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    qemu_free(buf);
 | 
					 | 
				
			||||||
    return -1;
 | 
					    return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user