Skip to content

Debug msgs#299

Open
andrewbird wants to merge 6 commits into
dosemu2:masterfrom
andrewbird:debug-msgs
Open

Debug msgs#299
andrewbird wants to merge 6 commits into
dosemu2:masterfrom
andrewbird:debug-msgs

Conversation

@andrewbird

@andrewbird andrewbird commented Jul 5, 2026

Copy link
Copy Markdown
Member

1/ Some changes to make the debugging to dosemu logging compile after enabling lots of DEBUG_* defines.
2/ Tidy up some of the messages now that the logging function prefixes every write.
3/ Tweak the CI to collect and archive any failure logs that may occur.

Comment thread kernel/nls.c Outdated
Comment thread kernel/nls.c Outdated
Comment thread kernel/newstuff.c
Comment thread fdpp/thunks.cc Outdated
{
fdpp->print(FDPP_PRINT_LOG, format, vl);
if (format[0] == '@')
fdpp->print(FDPP_PRINT_LOG_NOPREFIX, format + 1, vl);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add flag, shift it to
16 to not clash with the value.

f_node's f_count field was removed back in 2009 (bfdad2a),
so remove its use from debug message and the corresponding text.
1/ Fix up the FAR string printing.
   Need to use standard format specifiers and convert args to be
   compatible.
2/ Fix up type width format specifiers.
Now that DebugPrintf are prefixed with "fdpp: " we need to prefix those
that should be appended.

Was:
=====
fdpp: SUBSTing from: C:\
fdpp: NLS: DosUpFMem(): len=11, f997:03c0="fdpp: \fdpp: Tfdpp: Efdpp: Sfdpp: Tfdpp: Ifdpp: Tfdpp: .fdpp: Bfdpp: Afdpp: Tfdpp: "
fdpp: NLS: nlsFUpMem()
fdpp: NLS: upMMem(): len=11, f997:03c0="fdpp: \fdpp: Tfdpp: Efdpp: Sfdpp: Tfdpp: Ifdpp: Tfdpp: .fdpp: Bfdpp: Afdpp: Tfdpp: "
fdpp: NLS: upMMem(): result="fdpp: \fdpp: Tfdpp: Efdpp: Sfdpp: Tfdpp: Ifdpp: Tfdpp: .fdpp: Bfdpp: Afdpp: Tfdpp: "

Now:
=====
fdpp: SUBSTing from: C:\
fdpp: NLS: DosUpFMem(): len=11, f997:03c0="\TESTIT.BAT"
fdpp: NLS: nlsFUpMem()
fdpp: NLS: upMMem(): len=11, f997:03c0="\TESTIT.BAT"
fdpp: NLS: upMMem(): result="\TESTIT.BAT"
@andrewbird

Copy link
Copy Markdown
Member Author

I have a crash in truename at adjust_far() once I enable the debugging. The trigger is a super long argument (128 chars) which actually was unnecessary so I have removed it in my dosemu branch. Not sure whether it's important, after all it's a ridiculous size, but I thought I'd mention it.

Comment thread fdpp/thunks.cc
va_list vl;
int prio = FDPP_PRINT_LOG;

if (strcmp("%s", format) == 0) { // The string has been preformatted and we

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be reasonable
to demand @ in a format string
itself. I'd like to avoid va_arg() here.

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

*** stack smashing detected ***: terminated
Wow! Can you provide a minimal
reproducer? I suppose maybe some
buffer overflow on vsprintf(), so maybe
you can also find it yourself. :)

@andrewbird

Copy link
Copy Markdown
Member Author

I suppose maybe some
buffer overflow on vsprintf(), so maybe
you can also find it yourself. :)

I already looked for a couple of hours, but my lack of C++ knowledge stops me from finding anything other than it occurs in the call adjust_far() in truename.

Wow! Can you provide a minimal
reproducer?

1/ Yes, use dosemu devel (still has the excessively long and unnecessary argument in the batch file testit.bat), with fdpp of this branch at c71328b (which is compilation fixes, and turning on of all DEBUG options, but none of my '@' shenanigans).
2/ Setup test as
env NO_TESTRUN=1 test/test_dosemu.py PPDOSGITTestCase.test_mfs_sfn_file_read.
3/ Run dosemu as
Start dosemu as whatever the above printed, but in my case I renamed the log file
bin/dosemu -f /tmp/test-imagedir/dosemu.conf -n -q -o crash.log -td --Fimagedir /tmp/test-imagedir
4/ Run test batchfile as is, but note the crash only occurs with set LFN=n
C:\>testit

Here's mine.

ajb@calypso:/clients/common/dosemu2.git$ bin/dosemu -f /tmp/test-imagedir/dosemu.conf -n -q -o crash.log -td --Fimagedir /tmp/test-imagedir
FDPP kernel 1.7 [GIT: 1.10-66-gc71328b8]
Kernel compatibility 7.10 - clang - FAT32 support

Written by @stsp, FDPP project.
Based on FreeDOS sources (C) Pasquale J. Villani and The FreeDOS Project.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

C: HD1, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=    10 MB
D: HD2, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=    10 MB
E: HD3, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=  2000 MB
F: HD4, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=  2000 MB
G: HD5, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=  2000 MB
EMUFS host file and print access, non-resident driver mode                     
dosemu XMS 3.0 & UMB support enabled
dosemu EMS driver rev 0.9 installed.
dosemu CDROM driver installed (V0.2)
Process 0 starting: F:\command.com /e:384 /p /k %FDPP_AUTOEXEC% /M2
"Warning: USERDRV not set"

FreeDOS userspace tools can be installed with: insfdusr

BLASTER=A220 I5 D1 H5 P300 T6
MIDI=SYNTH:2 MAP:E MODE:0
Welcome to dosemu2!
    Build 2.0pre9-dev-20260706-4798-g5811247aa
Interactive Prompt!
C:\>testit
testit
C:\>set LFN=n
C:\>d:
D:\>c:\mfsread shrtname.txt FfaaE90dDC39F9C30Db4Ea75EbA420B1cB1DaEaedB89Cf51E3FA4B461878290EeCC0f42cd6e96fCBD6c66350edCc3054e04eB177eF1CDF7bf2D4e45D36225D28
Segmentation fault (Address not mapped to object [0x727e000a293a])
Terminated with signal 11

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member
This commit does not belong to any branch on this repository, and may belong to a fork outside
of the repository.

to start with.

Why is this a minimal reproducer?
Minimal reproducer is:

  • change this file this way
  • run dosemu as usual
  • observe its crashing

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

I suppose you meant this link:
andrewbird@c71328b

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member
$ bin/dosemu -f /tmp/test-imagedir/dosemu.conf -n -q -o crash.log -td --Fimagedir /tmp/test-imagedir
ERROR: --Fimagedir: /tmp/test-imagedir does not exist
ERROR: /tmp/test-imagedir/dosemu.conf is missing

@andrewbird

Copy link
Copy Markdown
Member Author

You didn't set up the like the instructions said
env NO_TESTRUN=1 test/test_dosemu.py PPDOSGITTestCase.test_mfs_sfn_file_read

@andrewbird

Copy link
Copy Markdown
Member Author

or more likely you did but didn't use the command it printed (what you posted looks like mine)

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

The problem is that _vsnprintf()
applies size to fmt argument,
i.e. it counts chars consumed,
not chars outputted. So %s is
counted like 1 char, which results
in overflow. Given that this code
is a pure crap, it uses a lot of global
vars and small buffers like
BYTE s[11], I don't see a quick fix.
Maybe the only reasonable thing
to do is to port from musl, but
you'll need to add a few things
there, like %P.
So will you work on that?

@andrewbird

Copy link
Copy Markdown
Member Author

Are you set on musl it looked quite complicated to extract the salient part? I looked for an alternative, this popped up https://github.com/nothings/stb/blob/master/stb_sprintf.h license is MIT or Public Domain.

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

I am not set for musl by
any means, but public domain?
I simply don't know.
If you show me some document
which says its fine for gpl projects -
then likely ok...

@andrewbird

Copy link
Copy Markdown
Member Author

No, it's Public Domain OR MIT, the user gets to choose which he wants to follow.

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

That is written in the end, and
not in the beginning...
Anyway, I haven't heard anything.
I'll just see MIT in your patch
(at the beginning!), and fare well.

@andrewbird

Copy link
Copy Markdown
Member Author

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

Ok, choose MIT and remove
the rest then.

@andrewbird

Copy link
Copy Markdown
Member Author

Will the new vsnprintf need to be in the kernel C code or in the C++ part?

@stsp

stsp commented Jul 7, 2026

Copy link
Copy Markdown
Member

Just replace the buggy prf.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants