Commit Graph

1307 Commits

Author SHA1 Message Date
Jan Engelhardt
e867977543 scripts: resolve strict aliasing violations in level DLLs
$GIT/scripts/LEVEL15.cpp: In function ‘void aMatCenPuzzleInit()’:
$GIT/scripts/LEVEL15.cpp:833:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  833 | #define MagicMatCenSwitchSequence (*((int *)(&User_vars[17])))
$GIT/scripts/LEVEL15.cpp:834:25: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  834 | #define MatCenStateA (*((int *)(&User_vars[0])))
...
$GIT/scripts/Level6.cpp: In function ‘void aPriestKeyEnter(int)’:
$GIT/scripts/Level6.cpp:910:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  910 | #define Var_ThereIsPlayerInPriestKeyPuzzle (*((int *)(&User_vars[7])))

Turn ``User_var`` into an array of std::variant, the latter of which can hold
either float or int. Savegames do not carry the necessary type information
which variant (float/int) is in use; instead, this is statically decided by
the level DLL logic on a per-index basis. This approach is retained for now.

A lot of ``Var_something = 0`` is used despite Var_something being
logically used as float, so we need to override op= to keep the
variant type as-is.
2024-09-09 15:42:00 +02:00
Jan Engelhardt
b6ef3b591a build: avoid repeat compilation of DallasFuncs.cpp
Due to ``#include "DallasFuncs.cpp"``, DF is recompiled 52 times.
Rework it to build just once. The compile time goes down for me
from 1m45.3s to 1m38.8s on my 1135G7 CPU running make -j8.
2024-09-09 15:29:40 +02:00
Jan Engelhardt
90110e43e9 build: resolve include issue with osiris_import.h
The switcheroo involving OSIRISEXTERN is unnecessary; if it is empty,
it is "extern" anyway.

One function, ``osicommon_Initialize``, is present twice and can lead
to duplicate definitions in the linker stage, which is probably what
the DallasFuncs.cpp comment alluded to. It is moved away into its own
.cpp file.
2024-09-09 15:29:38 +02:00
Jan Engelhardt
006c2fb4ec build: split osiris_vector.h into header and implementation
Both e.g. AIGame3.cpp and DallasFuncs.cpp include
``osiris_vector.h``. Right now, this is not a problem because
DallasFuncs.cpp is not compiled itself, but included from
AIGame3.cpp, in other words, it is all just one translation unit.

I have a plan to do away with ``#include "DallasFuncs.cpp"``, which
means the linker invocation for AIGame3.so will have at least two
translation units, and thus two definitions of the osiris vector
functions, which is not allowed.

This also has the side-effect to reduce compile-time a little,
from 1m57.5s to 1m48.7s on my 1135G7 CPU using `make -j8`.
2024-09-09 14:57:44 +02:00
Jan Engelhardt
ea3f11b6b5 scripts: remove unused files
"lnx" is not mentioned anywhere in CMakeLists.txt, so it also does
not appear on the compiler command lines, which means it is wholly
unused.
2024-09-09 14:35:06 +02:00
Jan Engelhardt
7a53958617 scripts: delete extraneous prototypes in level15 code
I want to namespace the stuff in DallasFuncs.cpp, and when I do that,
there comes about an ambiguity between ``NewNamespace::aUserFlagSet``
and the ``::aUserFlagSet`` declared by LEVEL15 (also ``qUserFlag``).

Due to ``#include "DallasFuncs.cpp"``, LEVEL15.cpp already has a
declaration (and definition) for ``aUserFlagSet``, and so we can jsut
remove the two lines.
2024-09-09 12:55:27 +02:00
Jan Engelhardt
b7b2f1e9aa Delete unused fixed math functions
gcc warns about strict aliasing violations in fix.cpp:

fix/fix.cpp: In function "int FloatRound(float)":
fix/fix.cpp:157:14: warning: dereferencing type-punned pointer will
break strict-aliasing rules [-Wstrict-aliasing]
  157 |   return ((*((int *)&nf)) & 0x7FFFFF) - 2048;

But these functions and then some are unused, so delete them altogether.
2024-09-09 12:55:27 +02:00
Azamat H. Hackimov
c003a98835
Merge pull request #579 from jengelh/dedi
Resolve out-of-bounds accesses with dedicated server code [ASAN]

fixes #571
2024-09-09 13:33:29 +03:00
Jan Engelhardt
b9fbee0e25 Resolve out-of-bounds accesses in DLLMultiInit
vp[26] is `int *`, so it tries to read 4 bytes on amd64, even though
TCP_Active, which is behind vp[26] is just a bool and 1 byte.

==95927==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000004734f40 at pc 0x7f4f8d93b952 bp 0x7ffc57f191b0 sp 0x7ffc57f191a8
READ of size 4 at 0x000004734f40 thread T0
    f0 DLLMultiInit $GIT/netcon/includes/mdllinit.h:314
    f1 LoadMultiDLL(char const*) $GIT/Descent3/multi_dll_mgr.cpp:690
    f2 RunServerConfigs $GIT/Descent3/dedicated_server.cpp:236
    f3 LoadServerConfigFile() $GIT/Descent3/dedicated_server.cpp:357
    f4 InitDedicatedServer $GIT/Descent3/init.cpp:1778
    f5 InitD3Systems2(bool) $GIT/Descent3/init.cpp:1952
    f6 Descent3() $GIT/Descent3/descent.cpp:504
    f7 oeD3LnxApp::run() $GIT/Descent3/sdlmain.cpp:151

0x000004734f41 is located 0 bytes after global variable 'TCP_active' defined in '$GIT/networking/networking.cpp:383:6' (0x4734f40) of size 1
SUMMARY: AddressSanitizer: global-buffer-overflow $GIT/netcon/includes/mdllinit.h:314 in DLLMultiInit
2024-09-09 12:15:05 +02:00
Jan Engelhardt
009645ac83 Switch netgame_info::server_config_name to dynamically allocated
Resolve an out-of-bounds write in LoadServerConfigFile.
A sufficiently long path,

	descent3 -dedicated /home/jengelh/.config/descent3/dedicated.conf

causes the game server to exit with

	Error loading connection DLL 'cated.conf'

Which hints at a buffer overflow.
2024-09-09 12:15:04 +02:00
Jan Engelhardt
30ef025e72 Resolve out-of-bounds-access in hlsoundlib
$GIT/sndlib/hlsoundlib.cpp:943:54: runtime error: index -1 out of bounds for type 'float [40]'
2024-09-09 10:46:24 +02:00
Jan Engelhardt
69dbf5bca7 Resolve alloc-dealloc-mismatch in CFile::FreeSymbols
==89545==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x5020001007f0
    f0 operator delete(void*, unsigned long) (/lib64/libasan.so.8+0xfe1f8)
    f1 InfFile::FreeSymbols() $GIT/cfile/inffile.cpp:63
    f2 InfFile::Close() $GIT/cfile/inffile.cpp:115
    f3 LoadServerConfigFile() $GIT/Descent3/dedicated_server.cpp:355

0x5020001007f0 is located 0 bytes inside of 11-byte region [0x5020001007f0,0x5020001007fb)
allocated by thread T0 here:
    f0 operator new[](unsigned long) (/lib64/libasan.so.8+0xfd458)
    f1 InfFile::AddSymbol(char const*, char const*) $GIT/cfile/inffile.cpp:49
    f2 InfFile::ParseLine(char*, int) $GIT/cfile/inffile.cpp:187
2024-09-09 10:38:17 +02:00
Jan Engelhardt
dfa0560aff dedicated: resolve out-of-bounds access during config parse
ASAN reports:

$GIT/Descent3/dedicated_server.cpp:350:24: runtime error: index 1024
out of bounds for type 'cvar_entry [36]'
$GIT/Descent3/dedicated_server.cpp:350:14: runtime error: load of
address 0x000001e677c0 with insufficient space for an object of type
'const char *'

This can happen if a line in the .cfg starts with a '#'.
2024-09-09 10:38:17 +02:00
Louis Gombert
40aae150b3
Merge pull request #577 from jengelh/tu
Consolidate duplicated `struct obj_sort_item`
2024-09-09 08:58:44 +02:00
Jan Engelhardt
bb1d6f6f85 Resolve out-of-bounds access at start of level 10
Descent3/aipath.cpp:663:40: runtime error: index -1 out of bounds for type
'short unsigned int [5]'
2024-09-09 08:42:49 +02:00
Jan Engelhardt
26e5cfa2d5 Consolidate duplicated struct obj_sort_item 2024-09-09 08:31:14 +02:00
Louis Gombert
6ad7a3d5cb
Merge pull request #575 from jengelh/fvi_room
Rework fvi_room patch
2024-09-08 23:19:31 +02:00
Louis Gombert
f34c8e51aa
Merge pull request #572 from jengelh/crashes.3
Resolve 2 ASAN crashes
2024-09-08 23:11:51 +02:00
Louis Gombert
dfc192ac81
Merge pull request #548 from pzychotic/fix-errors
Fix small collection of errors
2024-09-08 22:41:46 +02:00
Jan Engelhardt
b7e3652c42 Rework fvi_room patch
In Retribution level 15, the cinematic animation would not start
playing when entering Dravis's room (after defating Hellion).

Fixes: cb5c2913b2
2024-09-08 17:57:06 +02:00
Jan Engelhardt
cf41191f78 Resolve ODR violation between two TUs
Descent3/render.cpp:2989:8: warning: type "struct obj_sort_item" violates the C++ One Definition Rule [-Wodr]
 2989 | struct obj_sort_item {
Descent3/terrainrender.cpp:943:8: note: a different type is defined in another translation unit
2024-09-08 13:52:21 +02:00
Jan Engelhardt
bbb74b976b Resolve assertion in multisafe
During Retribution level 13, after about 5 minutes when some timed
level script seems to run and the message "GB: Engine malfunction" is
printed, there is also an assert:

Assertion failure at msafe_CallFunction ($GIT/Descent3/multisafe.cpp:1719), triggered 1 time:
  'mstruct->id != -1'

The result from SpewCreate is -1 because there are no more gun slots
available, i.e. this condition is where the function exited thru:

	if (spew->gp.gunpoint < 0 || spew->gp.gunpoint >= pm->n_guns)
2024-09-07 23:13:32 +02:00
Jan Engelhardt
6c0dd1ad9d Resolve out-of-bounds access on Retribution level 13
ASAN complained:

$GIT/Descent3/BOA.cpp:443:54: runtime error: index -1 out of bounds for type 'float [40]'

At that particular time, important variables had these values:

cur_room=36 this_portal=-1
2024-09-07 23:11:51 +02:00
Jan Engelhardt
10a03e71ef Resolve out-of-bounds access in GoalAllocSlot
(Happened during Retribution level 8 in the ship hangar with the docking clamps.)

Descent3/AIGoal.cpp:938:28: runtime error: index -1 out of bounds for type 'goal [10]'
2024-09-07 23:02:41 +02:00
Jan Engelhardt
31e9938eed Resolve out-of-bounds access in DrawSplinterObject
Occurs in Retribution level 7 whenever a FS440 "Six Gun" robot
is destroyed.

smfaces[facenum=0].texnum=-1
Descent3/splinter.cpp:73:74: runtime error: index -1 out of bounds for type "short int [35]"
2024-09-07 23:02:41 +02:00
Jan Engelhardt
76c8fa7038 Resolve out-of-bounds access in BOA
Descent3/BOA.cpp:451:53: runtime error: index -1 out of bounds for type 'float [40]'
2024-09-07 23:02:39 +02:00
Jan Engelhardt
ed91f6f411 Resolve signed integer overflow warning
Adding to ``total`` can cause signed integer overflow, which is
undefined, and ASAN warns:

Descent3/terrain.cpp:300:11: runtime error: signed integer overflow:
2147421608 + 65586 cannot be represented in type 'int'

Switch the variable unsigned; the bit patterns in practice will be
the same, but unsigned wraparound is well-defined. Finally, convert
the result back to signed, which should be allowed, cf.
http://eel.is/c++draft/conv.integral#3 .
2024-09-07 23:02:14 +02:00
Jan Engelhardt
0e9982fe72 Resolve signed multiplication overflow when drawing Omega gun fire
Descent3/WeaponFire.cpp:2130:7: runtime error: signed integer overflow:
520857 * 5000 cannot be represented in type "int"

This is about how the Omega's gun ray is animated, and given there is
some sine wave stuff going on, it is fair to say that the intent was
for the value to wraparound. However, wraparound in C++ is only
well-defined for unsigned types, so switch it.
2024-09-07 23:02:13 +02:00
Jan Engelhardt
765f616d7c Force makeshort/makeword to treat inputs as unsigned
ASAN says:

linux/lnxcontroller.cpp:484:12: runtime error: left shift of negative value -1
(in other words, "-1 << x", not "x << (-1)")

Bitwise AND/OR often only make sense for unsigned quantities, so
enforce exactly that kind of treatment.
2024-09-07 23:02:13 +02:00
Louis Gombert
9fcd4e7857
Merge pull request #558 from jengelh/crashes.2
Fix some 8 other game crashes [ASAN]
2024-09-07 21:57:49 +02:00
Louis Gombert
7c9fd48ea6
Merge pull request #566 from jengelh/scorch
Repair non-sensical scorch iterations
2024-09-07 21:49:34 +02:00
Louis Gombert
8c39002076
Merge pull request #567 from jengelh/spello
Fix a bunch of spellos in comments and strings
2024-09-07 21:48:51 +02:00
Thomas Roß
edb596b731 [Comment] Fixed messed up character encoding in comment 2024-09-07 16:58:36 +02:00
Thomas Roß
582869bc50 [DMFC] Fixed missing va_end calls in case of function early outs 2024-09-07 16:58:08 +02:00
Thomas Roß
68334c54f4 [Linux] Fixed too many parameters to fprintf call 2024-09-07 16:57:37 +02:00
Thomas Roß
fcccc9aafa [DDGR] Fixed accidental assignment in 'if' statement 2024-09-07 16:57:11 +02:00
Taylor Richards
43b691dbc5
add support for PXO's NAT hole punch 2024-09-06 13:28:50 -04:00
Christian Baumann
daebe15442 fix wrong type 2024-09-05 23:36:20 +02:00
Christian Baumann
7ff07b137a init 2024-09-05 17:48:42 +02:00
Azamat H. Hackimov
d185ab9514 Fix memory leaks in dedicated mode 2024-09-04 14:17:02 +03:00
Jan Engelhardt
5f0bdf8184 Fix spello "it's" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
38b835a03b Fix spello "its" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
a3a31c77a2 Fix spello "seperate.." 2024-09-03 13:26:51 +02:00
Jan Engelhardt
4d9ff9cdc6 Fix some one-off spellos 2024-09-03 13:26:51 +02:00
Jan Engelhardt
1c32732f59 Fix spello "wierd" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
a09efdaf20 Fix spello "conforming" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
96c787bfb2 Fix spello "interative why" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
b14470bbff Fix spello "independan.." 2024-09-03 13:26:51 +02:00
Jan Engelhardt
1036c3c677 Fix spello "targett" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
edbde82918 Fix spello "agression" 2024-09-03 13:26:51 +02:00