Menu

#433 crash on divide by zero using int 21h ah=23h

0.74
fixed
Qbix
None
5
2016-02-09
2015-12-27
John Comeau
No

while solving http://stackoverflow.com/questions/34435741/fcb-and-int-21h-function-23h/34443223#34443223, I found a bug in dosbox wherein a divide by zero error crashes the emulator, while attempting to populate a FCB using service 23h.

~~~~CONFIG:Loading primary settings from config file /home/jcomeau/.dosbox/dosbox-0.74.conf
[New Thread 0xf23a9b40 (LWP 20383)]
MIXER:Got different values from SDL: freq 44100, blocksize 512
ALSA:Can't subscribe to MIDI port (65:0) nor (17:0)
MIDI:Opened device:none

Program received signal SIGFPE, Arithmetic exception.
0x080d9673 in ?? ()
(gdb) bt

0 0x080d9673 in ?? ()

1 0x080d1eeb in ?? ()

2 0x0804f7bc in ?? ()

3 0x0805010e in ?? ()

4 0x080553ce in ?? ()

5 0x08228c23 in ?? ()

6 0x082268ae in ?? ()

7 0x08220abe in ?? ()

8 0x082217cb in ?? ()

9 0x082214c1 in ?? ()

10 0x0804e9ea in main ()

(gdb) ~~~~

the problem is caused by not filling in the rec_size field of the FCB, as MSDOS would do, and as your own DOS_FCBOpen function does. I believe the minimal patch that solves the problem involves making DOS_FCBOpen return a handle instead of a boolean, and using that instead of the current code for service 23h.

here is what it should show, using the DOS debug program from https://sites.google.com/site/pcdosretro/enhdebug, and does after patching. before the patch, it would crash right after executing int 21:

Discussion

  • John Comeau

    John Comeau - 2015-12-27

    the formatting broke, sorry. I'll add the patch and screenshot again here.

     
  • ripsaw8080

    ripsaw8080 - 2015-12-28

    Those "return (Bit16u) false" lines in your patch gave me a chuckle.

    Anyway, "if (rec_size==0) rec_size=128;" seems a much simpler patch...

     
  • John Comeau

    John Comeau - 2015-12-28

    hey, I'm only an occasional and reluctant C programmer :^)

    whatever works is OK with me, but I prefer the DRY principle.

     

    Last edit: John Comeau 2015-12-28
  • John Comeau

    John Comeau - 2016-01-01

    new patch without the comical (Bit16u) false casts, after refreshing my memory at stackoverflow.

     
  • Qbix

    Qbix - 2016-02-09
    • status: open --> fixed
    • assigned_to: Peter Veenstra
     
  • Qbix

    Qbix - 2016-02-09

    fixed in 3962

     

Log in to post a comment.

Monday.com Logo