Commit 27c3f2cb9bf2112b82edac898094e0a39e6efca1

Authored by bellard
1 parent a07cf92a

buffer overflow fix - handle case where stdin is closed (Rusty Russell)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@397 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 7 additions and 3 deletions
... ... @@ -3283,8 +3283,8 @@ CPUState *cpu_gdbstub_get_env(void *opaque)
3283 3283  
3284 3284 int main_loop(void *opaque)
3285 3285 {
3286   - struct pollfd ufds[2], *pf, *serial_ufd, *net_ufd, *gdb_ufd;
3287   - int ret, n, timeout;
  3286 + struct pollfd ufds[3], *pf, *serial_ufd, *net_ufd, *gdb_ufd;
  3287 + int ret, n, timeout, serial_ok;
3288 3288 uint8_t ch;
3289 3289 CPUState *env = global_env;
3290 3290  
... ... @@ -3296,6 +3296,7 @@ int main_loop(void *opaque)
3296 3296 term_init();
3297 3297 }
3298 3298  
  3299 + serial_ok = 1;
3299 3300 for(;;) {
3300 3301 ret = cpu_x86_exec(env);
3301 3302 if (reset_requested)
... ... @@ -3310,7 +3311,7 @@ int main_loop(void *opaque)
3310 3311 /* poll any events */
3311 3312 serial_ufd = NULL;
3312 3313 pf = ufds;
3313   - if (!(serial_ports[0].lsr & UART_LSR_DR)) {
  3314 + if (serial_ok && !(serial_ports[0].lsr & UART_LSR_DR)) {
3314 3315 serial_ufd = pf;
3315 3316 pf->fd = 0;
3316 3317 pf->events = POLLIN;
... ... @@ -3337,6 +3338,9 @@ int main_loop(void *opaque)
3337 3338 n = read(0, &ch, 1);
3338 3339 if (n == 1) {
3339 3340 serial_received_byte(&serial_ports[0], ch);
  3341 + } else {
  3342 + /* Closed, stop polling. */
  3343 + serial_ok = 0;
3340 3344 }
3341 3345 }
3342 3346 if (net_ufd && (net_ufd->revents & POLLIN)) {
... ...