From 76f0c9304f5a314b9e6b3b9c736530aab70d4859 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 18 Aug 2024 15:35:04 +1200 Subject: [PATCH 1/5] Fix use of uninitialized variable --- kermit/k95/ckuus4.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kermit/k95/ckuus4.c b/kermit/k95/ckuus4.c index 247999ac..525e9198 100644 --- a/kermit/k95/ckuus4.c +++ b/kermit/k95/ckuus4.c @@ -14206,23 +14206,25 @@ char * /* Evaluate builtin variable */ p++; } p = vvbuf; + #ifndef VMS - if (p > vvbuf) { /* Directory termination character */ - c = + c = #ifdef MAC - ':' + ':' #else #ifdef datageneral - ':' + ':' #else #ifdef STRATUS - '>' + '>' #else - '/' + '/' #endif /* STRATUS */ #endif /* datageneral */ #endif /* MAC */ - ; + ; + + if (p > vvbuf) { /* Directory termination character */ if (*(p-1) != c) { /* Add it to the end of the */ *p++ = c; /* string if it was not already */ *p = NUL; /* there */ From af5186e63816a2839fc8523ba3956517a5bae5d5 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 18 Aug 2024 18:33:22 +1200 Subject: [PATCH 2/5] Fix extra runtime checks option --- kermit/k95/ckoker.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kermit/k95/ckoker.mak b/kermit/k95/ckoker.mak index 3a8c6462..971d6d7d 100644 --- a/kermit/k95/ckoker.mak +++ b/kermit/k95/ckoker.mak @@ -68,7 +68,7 @@ COMMON_CFLAGS = /MD !if "$(CKF_DEV_CHECKS)" == "yes" # Enable extra runtime checks. These only work with a debug build and # Visual C++ 2002 and newer -COMMON_CFLAGS = /RTCsu +COMMON_CFLAGS = $(COMMON_CFLAGS) /RTCsu !else COMMON_OPTS = /Ox !endif From e34d33a0002b15d9c10f4c30b8820be2c70c5425 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 18 Aug 2024 20:46:28 +1200 Subject: [PATCH 3/5] Include PDB files with release builds (#289) --- .github/workflows/build.yml | 3 ++ kermit/k95/ckoker.mak | 74 +++++++++++++++++++++++++++---------- kermit/k95/kui/makefile | 28 ++++++++++++++ kermit/k95/mkdist.bat | 3 ++ 4 files changed, 88 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3e9d6a4..40ef4757 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -522,6 +522,7 @@ jobs: set CKF_SSH_DLL_VARIANT=g call mksshdll.bat ren k95ssh.dll k95sshg.dll + ren k95ssh.pdb k95sshg.pdb del k95ssh.res if "%CKB_XP_COMPATIBLE%" NEQ "yes" goto :noxp @@ -530,6 +531,7 @@ jobs: set CKF_SSH_DLL_VARIANT=x call mksshdll.bat ren k95ssh.dll k95sshx.dll + ren k95ssh.pdb k95sshx.pdb del k95ssh.res REM XP, GSSAPI-enabled @@ -537,6 +539,7 @@ jobs: set CKF_SSH_DLL_VARIANT=gx call mksshdll.bat ren k95ssh.dll k95sshgx.dll + ren k95ssh.pdb k95sshgx.pdb del k95ssh.res :noxp diff --git a/kermit/k95/ckoker.mak b/kermit/k95/ckoker.mak index 3a8c6462..d51668a7 100644 --- a/kermit/k95/ckoker.mak +++ b/kermit/k95/ckoker.mak @@ -187,11 +187,11 @@ CKB_STATIC_CRT = yes # Standard windows headers from MinGW that don't come with OpenWatcom: INCLUDE = $(INCLUDE);ow\; -!endif +!endif # EndIf CMP == OWCL !if ($(MSC_VER) < 80) !error Unsupported compiler version. Visual C++ 1.0 32-bit edition or newer required. -!endif +!endif # EndIf MSC_VER < 80 # TODO: Much of this compiler flag work should be applied to the KUI Makefile # too @@ -200,18 +200,18 @@ INCLUDE = $(INCLUDE);ow\; # then tell the linker we're targeting x86-64 !if "$(TARGET_CPU)" == "x86-64" LDFLAGS = $(LDFLAGS) /MACHINE:X64 -!endif +!endif # EndIf TARGET_CPU == x86-64 !if "$(TARGET_CPU)" == "AXP64" # This compiler is capable of targeting AXP64, so add the build flag to do that. COMMON_CFLAGS = $(COMMON_CFLAGS) /Ap64 LINKFLAGS = $(LINKFLAGS) /MACHINE:ALPHA64 -!endif +!endif # EndIf TARGET_CPU == AXP64 !if ("$(DEBUG)" != "-DNDEBUG") && ($(MSC_VER) <= 130) # This debug flag is only valid on Visual C++ 6.0 and older. LINKFLAGS = $(LINKFLAGS) /debugtype:both -!endif +!endif # EndIf DEBUG != -DNDEBUG and MSC_VER <= 130 !if ($(MSC_VER) >= 170) && ($(MSC_VER) <= 192) # Starting with Visual C++ 2012, the default subsystem version is set to 6.0 @@ -221,23 +221,57 @@ LINKFLAGS = $(LINKFLAGS) /debugtype:both # version to 5.1 so the generated binaries are compatible. SUBSYSTEM_CONSOLE=console,5.1 SUBSYSTEM_WIN32=windows,5.1 -!endif +!endif # EndIf MSC_VER >= 170 and MSC_VER <= 192 -!if ($(MSC_VER) == 80) && ("$(MSC_VER)" == "AXP") +!if ($(MSC_VER) == 80) && ("$(TARGET_CPU)" == "AXP") # The linker included with the NT 3.50 SDK for Alpha can't handle # K95 (complains "LINK : error LNK1155: Special symbol 'end' already defined.") # So to support using a newer linker that has less problems, we'll set # the subsystem version so the result still works on NT 3.1/3.50 SUBSYSTEM_CONSOLE=console,3.1 SUBSYSTEM_WIN32=windows,3.1 -!endif +!endif # EndIf MSC_VER == 80 and TARGET_CPU == AXP !if ($(MSC_VER) > 90) !if "$(TARGET_CPU)" != "MIPS" # This flag isn't valid on Visual C++ 4.0 MIPS (or, I assume, any other version) COMMON_OPTS = $(COMMON_OPTS) /GA -!endif -!endif +!endif # EndIf TARGET_CPU != MIPS +!endif # EndIf MSC_VER > 90 + +# PDB Generation Stuff + +!if ($(MSC_VER) < 180) && ("$(ISJOM)" == "yes") && ("$(CKB_MAKE_PDB)" != "yes") +!message Make is JOM and compiler is older than Visual C++ 2013. Can't reliably +!message synchronise writes to a PDB file with this compiler. Disabling PDB +!message generation. override with: set CKB_MAKE_PDB=yes but you may get build +!message errors. +CKB_MAKE_PDB=no +!endif # EndIf MSC_VER < 180 and ISJOM == yes and CKB_MAKE_PDB != yes + +!if "$(CKB_MAKE_PDB)" != "no" +# Lets see if we can make a PDB file! This requires Visual C++ 4.0 or newer. +!if ($(MSC_VER) > 90) +!message Enabling PDB generation + +COMMON_CFLAGS = $(COMMON_CFLAGS) /Zi +LDDEBUG = $(LDDEBUG) /DEBUG /INCREMENTAL:NO /OPT:REF + +# /OPT:ICF is new in Visual C++ 5.0 +!if ($(MSC_VER) >= 110) +LDDEBUG = $(LDDEBUG) /OPT:ICF +!endif # EndIf MSC_VER >= 110 + +# /FS is required to synchronise writes to a PDB when doing parallel builds with +# something like JOM. It was introduced in Visual C++ 2013. +!if ($(MSC_VER) >= 180) +COMMON_CFLAGS = $(COMMON_CFLAGS) /FS +!endif # EndIf MSC_VER >= 180 + +!endif # EndIf MSC_VER > 90 +!endif # EndIf CKB_MAKE_PDB != no + +# End PDB Generation Stuff !if ($(MSC_VER) < 140) # These flags and options are deprecated or unsupported @@ -246,13 +280,13 @@ COMMON_OPTS = $(COMMON_OPTS) /GA # /GX- is new in Visual C++ 2.0 !if ($(MSC_VER) > 80) COMMON_CFLAGS = $(COMMON_CFLAGS) /GX- -!endif +!endif # EndIf MSC_VER > 80 !if ($(MSC_VER) < 100) # Visual C++ 2.0 and 1.0 32-bit edition don't support these flags, so don't # use them. CFLAG_GF= -!endif +!endif # EndIf MSC_VER < 100 COMMON_CFLAGS = $(COMMON_CFLAGS) /Ze # These are: /Ze Enable extensions (default) @@ -263,19 +297,19 @@ COMMON_CFLAGS = $(COMMON_CFLAGS) /Ze # So only generate PCH files when nmake instead of jom. !if "$(ISJOM)" == "no" COMMON_CFLAGS = $(COMMON_CFLAGS) /YX -!endif +!endif # EndIf ISJOM == no !if "$(TARGET_CPU)" == "x86" # Optimise for Pentium COMMON_OPTS = $(COMMON_OPTS) /G5 -!endif +!endif # EndIf TARGET_CPU == x86 -!else +!else # Else MSC_VER < 140 COMMON_CFLAGS = $(COMMON_CFLAGS) /EHs-c- # These are: /EHs-c- Enable C++ Exception handling (replaces /GX-) -!endif +!endif # EndIf MSC_VER < 140 -!endif +!endif # EndIf PLATFORM == NT RCDEFINES=$(RC_FEATURE_DEFS) /dCOMPILER_$(CMP) !if "$(SSH_LIB)" == "" @@ -386,7 +420,7 @@ msvc: LDFLAGS="" \ PLATFORM="NT" \ NOLINK="/c" \ - LINKFLAGS="/nologo /SUBSYSTEM:$(SUBSYSTEM_CONSOLE) /MAP /OPT:REF" DEF="cknker.def" + LINKFLAGS="/nologo /SUBSYSTEM:$(SUBSYSTEM_CONSOLE) /MAP /OPT:REF $(LDDEBUG)" DEF="cknker.def" !if "$(CKF_DYNAMIC_SSH)" == "yes" msvc-sshdll: @@ -540,7 +574,7 @@ k95gd: LDFLAGS="" \ PLATFORM="NT" \ NOLINK="-c" \ - LINKFLAGS="/nologo /MAP /DEBUG:full /SUBSYSTEM:$(SUBSYSTEM_WIN32)" \ + LINKFLAGS="/nologo /MAP /DEBUG /SUBSYSTEM:$(SUBSYSTEM_WIN32)" \ DEF="cknker.def" k95g: @@ -555,7 +589,7 @@ k95g: LDFLAGS="" \ PLATFORM="NT" \ NOLINK="-c" \ - LINKFLAGS="/nologo /SUBSYSTEM:$(SUBSYSTEM_WIN32)" \ + LINKFLAGS="/nologo /SUBSYSTEM:$(SUBSYSTEM_WIN32) $(LDDEBUG)" \ DEF="cknker.def" ################### OS/2 TARGETS ################### diff --git a/kermit/k95/kui/makefile b/kermit/k95/kui/makefile index 2c7a9b66..a5d474a3 100644 --- a/kermit/k95/kui/makefile +++ b/kermit/k95/kui/makefile @@ -18,6 +18,34 @@ COMMON_CFLAGS = /D_MT /QmipsOb5000 CKB_STATIC_CRT = yes !endif +# PDB Generation Stuff + +!if ($(MSC_VER) < 180) && ("$(ISJOM)" == "yes") && ("$(CKB_MAKE_PDB)" != "yes") +!message Make is JOM and compiler is older than Visual C++ 2013. Can't reliably +!message synchronise writes to a PDB file with this compiler. Disabling PDB +!message generation. override with: set CKB_MAKE_PDB=yes but you may get build +!message errors. +CKB_MAKE_PDB=no +!endif # EndIf MSC_VER < 180 and ISJOM == yes and CKB_MAKE_PDB != yes + +!if "$(CKB_MAKE_PDB)" != "no" +# Lets see if we can make a PDB file! This requires Visual C++ 4.0 or newer. +!if ($(MSC_VER) > 90) +!message Enabling PDB generation + +COMMON_CFLAGS = $(COMMON_CFLAGS) /Zi + +# /FS is required to synchronise writes to a PDB when doing parallel builds with +# something like JOM. It was introduced in Visual C++ 2013. +!if ($(MSC_VER) >= 180) +COMMON_CFLAGS = $(COMMON_CFLAGS) /FS +!endif # EndIf MSC_VER >= 180 + +!endif # EndIf MSC_VER > 90 +!endif # EndIf CKB_MAKE_PDB != no + +# End PDB Generation Stuff + all: $(OUTDIR)\$(PROJ).exe KUIOBJS = \ diff --git a/kermit/k95/mkdist.bat b/kermit/k95/mkdist.bat index 2ff19def..bce816d9 100644 --- a/kermit/k95/mkdist.bat +++ b/kermit/k95/mkdist.bat @@ -22,11 +22,14 @@ if not exist dist\users\NUL mkdir dist\users @echo Move build outputs... move *.exe dist +move *.pdb dist +if exist dist\nullssh.pdb delete dist\nullssh.pdb move k95ssh*.dll dist if exist k95crypt.dll move k95crypt.dll dist copy *.manifest dist copy iksd.ksc dist\iksd.ksc.sample ren dist\cknker.exe k95.exe +ren dist\cknker.pdb k95.pdb ren dist\cknker.exe.manifest k95.exe.manifest del dist\cknker.exe.manifest REM del dist\ctl3dins.exe -- this can trip up virus scanners but its required by the dialer From 4fe7bb9ca9a78cdba51f4f4fef1d0ac6e24fb5f1 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 19 Aug 2024 12:41:44 +1200 Subject: [PATCH 4/5] Fix fopen crashing due to file mode cache hint Fixed #288 --- doc/changes.md | 3 ++- kermit/k95/ckuus7.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/changes.md b/doc/changes.md index 959a1188..1f82575d 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -23,7 +23,8 @@ Nothing yet None yet ### Fixed bugs -None yet +* Fix `fopen` causing a crash. This issue seems to have come in some recent + version of the Microsoft C Runtime. ### Other Source Changes None yet diff --git a/kermit/k95/ckuus7.c b/kermit/k95/ckuus7.c index f232fb3a..52ff91b2 100644 --- a/kermit/k95/ckuus7.c +++ b/kermit/k95/ckuus7.c @@ -11890,6 +11890,12 @@ z_open(name, flags) char * name; int flags; if (!mode[0]) /* Check for illegal combinations */ return(z_error = FX_BOM); } + +#ifdef NT + ckstrncat(mode,"S",8); /* S is also known as _O_SEQUENTIAL */ + debug(F110, "z_open fopen", mode, 0); +#endif /* NT */ + if (!z_inited) { /* If file structs not inited */ debug(F101,"z_open z_maxchan 1","",z_maxchan); #ifdef UNIX @@ -12010,12 +12016,22 @@ z_open(name, flags) char * name; int flags; z_file[n] = NULL; return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error code */ } +#ifdef COMMENT + /* + * 2024-08-19 DavidG: This started crashing on Windows 11 in CKW Beta 6. The + * call to setmode seems ok, it just doesn't like O_SEQUENTIAL anymore. Not + * sure if this is something unsupported now, or if its a bug in the CRT. + * For some reason I've not looked into too closely I'm not even getting + * O_SEQUENTIAL defined on my local PC, while its clearly there on the + * Gitub build agents. + */ #ifdef NT #ifdef O_SEQUENTIAL if (t) /* Caching hint for NT */ _setmode(_fileno(t),O_SEQUENTIAL); #endif /* O_SEQUENTIAL */ #endif /* NT */ +#endif /* COMMENT */ z_nopen++; /* Open, count it. */ z_file[n]->z_fp = t; /* Stash the file pointer */ From b6bf33698fca28ad26c31288e5747bcc14095853 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 19 Aug 2024 12:49:27 +1200 Subject: [PATCH 5/5] Fix hitting backspace in an empty search-in-buffer crashing Fixes #290 --- doc/changes.md | 1 + kermit/k95/ckoco3.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/changes.md b/doc/changes.md index 1f82575d..1576d915 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -25,6 +25,7 @@ None yet ### Fixed bugs * Fix `fopen` causing a crash. This issue seems to have come in some recent version of the Microsoft C Runtime. +* Fix hitting backspace in an empty search-in-buffer crashing ### Other Source Changes None yet diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index d0f62816..9390c5d9 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -7742,6 +7742,8 @@ gotojump( int vmode ) return; } +#define SEARCHSTRING_LEN 63 + BOOL search( BYTE vmode, BOOL forward, BOOL prompt ) { @@ -7750,7 +7752,7 @@ search( BYTE vmode, BOOL forward, BOOL prompt ) #else extern int inpcas[] ; #endif /* DCMDBUF */ - static char searchstring[63] = "" ; + static char searchstring[SEARCHSTRING_LEN] = "" ; CHAR x1; con_event evt ; int line = 1 ; @@ -7807,7 +7809,7 @@ search( BYTE vmode, BOOL forward, BOOL prompt ) } else if ( x1 >= ' ' && x1 <= 126 || x1 >= 128 /*always true: && x1 <= 255*/ ) { - if ( len >= 62 ) { + if ( len >= SEARCHSTRING_LEN - 1 ) { bleep(BP_WARN); } else { @@ -7817,7 +7819,11 @@ search( BYTE vmode, BOOL forward, BOOL prompt ) } else if ( x1 == 8 || x1 == 127 ) { - searchstring[len-1] = '\0' ; + if (len - 1 < 0) { + bleep(BP_WARN); + } else { + searchstring[len-1] = '\0' ; + } } else if ( x1 == 13 ) {