Commit Graph

72 Commits

Author SHA1 Message Date
Bart House
a607ea2b7f Revert "When fuzzing, use the number of moves as a proxy for the hour."
This reverts commit f75deae0bc.
2019-07-14 21:29:41 -07:00
Bart House
f7c956c35a Revert "Adding ptr_array data structure."
This reverts commit e665d3b850.
2019-07-14 21:12:59 -07:00
Bart House
4c1c247028 Revert "Fuzzer improvements."
This reverts commit 435f1c4626.
2019-07-14 21:10:39 -07:00
Bart House
435f1c4626 Fuzzer improvements.
phase_of_moon and friday_13th determined using rn2() instead of local
time if fuzzing.  Don't reseed using init_random() if fuzzing.  Allow
set_random to be called outside of hacklib.  rn2_on_display_rng uses
rn2 if fuzzing so that we have a single source of random that we can
ensure is reproducible.  Implement rul() that returns a random unsigned
long.  Fix bug in fuzzer handling of ntposkey which would cause us to use
unitialized values for x and y.  Added command line arguments to allow
auto starting and stopping of fuzzer.  Add a logging facility for the
fuzzer to use to record activity.  Added some scripts used to automate
fuzzer testing on windows.
2019-07-14 00:20:09 -07:00
Bart House
e665d3b850 Adding ptr_array data structure. 2019-07-13 16:08:08 -07:00
Bart House
f75deae0bc When fuzzing, use the number of moves as a proxy for the hour.
Every 1000 moves simulates one hour.
2019-07-04 18:06:56 -07:00
PatR
ed55fa23f6 hacklib.c tidbit
Describe 'trimspaces()' more accurately.
2019-03-15 01:45:10 -07:00
PatR
409343e8eb another warning fix
Only appeared when ISAAC64 was disabled.
2019-01-30 16:25:31 -08:00
nhmall
457e4b68aa merge Alex's dual rng proposal with the isaac64 rng code and adjust
This is branched from Alex's hallu-rng-stability branch,
with two build corrections (detect.c, zap.c), and merged
with  the isaac64 branch that we have ready to go.

Alex's dual rng is supported by setting up the array
of multiple isaac64 contexts.

I stuck with Alex's approach of passing the rng function
name around as the parameter (rng or rn2_on_display_rng)
for the new additional parameter needed for
set_random(), init_random(), reseed_random(),
and init_isaac64().
2019-01-28 19:43:55 -05:00
nhmall
0aa4d62a2c detect rng seed strength at runtime based on algorithm not compile time based on platform features 2019-01-28 10:32:57 +01:00
nhmall
0a430cab11 every platform provides sys_random_seed() and SYS_RANDOM_SEED goes away 2019-01-28 10:32:57 +01:00
nhmall
6c114640f5 some system-specific adjustments for RNG routines
move some system-specific seed-related stuff from hacklib.c to
a system-specific source file and #define SYS_RANDOM_SEED to
utilize it during build.

Windows changes for random seed generation using
crypto next gen (CNG) api routines.

Corresponding vms changes due to disentangling of VMS and
unix when the unix seed bits got moved (untested).
2019-01-28 10:02:08 +01:00
Patric Mueller
f9433b2a87 integrate isaac64 into nethack
Also removed the float code from isaac64 as they are not used in
NetHack.
2019-01-28 10:02:08 +01:00
Patric Mueller
52d4b1a1aa reseed during level change to prevent deduction of rng state
For platforms that read from the system's random number generator,
reseed during level change, before the map of a new level is created and
after level creation has finished.
2019-01-28 10:02:00 +01:00
Patric Mueller
86d694c61b read rng seed from random number source device
Linux and BSD system have random number source devices that can be used
as source for a unguessable seed source.

Other platforms fall back to generate the seed with gettime().
2019-01-28 10:01:45 +01:00
keni
d8c49ec9d1 Add updated copyright lines, part 1. 2018-04-25 15:00:13 -04:00
PatR
48af4fa259 static analyzer bit
I can't find the original message at the moment, but one of the things
that an analyzer complained about was the *s='\0' possibly assigning
to a Null pointer.  The superfluous test of 's' in the while condition
has fooled it into thinking that's possible when it's not.

if (s) {
  while (s && ...) {
    *s++ = ...
  }
  *s = '\0';
}
2018-02-17 18:54:52 -08:00
PatR
0bdbfaa580 strbuf cleanup
The expression '*cp-- = cp[-count]' is not valid C.  There's no sequence
point between the two references to 'cp', and the decrement side-effect
could occur before or after cp[-count] is resolved.

The functions were also using ANSI-style argument definitions.  The rest
is just reformatting.

It seems to me that the strbuf structure ought to have an allocation
size field in addition to the current length field.  Otherwise a string
which gets shortened will forget about the extra length available for
later expansion, potentially resulting in unnecessary reallocation.
2017-10-25 19:13:21 -07:00
Bart House
a588541a27 Win32GUI: Gather raw_print text and display it all in single dialog
Defined strbuf_t and related routines to support dynamically sized
strings. Modified strip_newline() to strip the last newline in a string
instead of the first.

Simplified splash window code using new strbuf_t.

Prior to exiting game, re-enable getreturn and call wait_synch() in
case there is buffered raw prints that must be displayed to user.
2017-10-25 10:34:27 +03:00
Pasi Kallinen
69f7a78dba Hilite Status: Improved
Allow defining multiple stops per field. Add hitpointbar.
2017-09-26 10:04:25 +03:00
PatR
964fd0fdbd dynamic format strings vulnerable to user input
This adds new utility routine strNsubst(), a more versatile version
of the existing strsubst(), that can replace the Nth occurrence of
a substring rather than just the first, and replaces all occurrences
if N is 0.

When working on vampire shape-shifting messages a few days ago I
noticed that a constructed pline/sprintf format was vulnerable to
the player giving the vampire a name with '%' in it and included
a fix for that.  This fixes two other instances of the same
vulnerability:  a monster with reflection triggering a floating
eye's gaze and the hero using a silver weapon against a silver-
hating monster.

I didn't do a lot of experimenting with the failure, just assigned
the name "foo%s" to the floating eye or the weapon.  The resulting
feedback for the relevant messages was garbled due to parameters
being substituted in the wrong place.  When that caused there to be
too few arguments to satisfy the format, the final message included
"null" for the missing one rather than triggering a crash while
trying to format something arbitrary from the stack.

I don't think these bugs provided sufficient user control to be
vulnerable to stack manipulation that does something naughty.

I found the dynamic format strings by searching for "%%".  There
may be others scattered around the code which don't have that as
an indicator....
2017-06-07 11:39:24 -07:00
Pasi Kallinen
680c8a542c Add key rebinding
This is a modified version of Jason Dorje Short's key rebinding
patch, and allows also binding special keys, such as the ones
used in getloc and getpos.

One of the ways to play NetHack on nethack.alt.org is via a HTML
terminal in browser. Unfortunately this means several ctrl-key
combinations cannot be entered, because the browser intercepts
those. Similar thing applies to some international keyboard layouts
on Windows. With this patch, the user can just rebind the command
to a key that works best for them.

I've tested this on Linux TTY, X11, and Windows TTY and GUI.
2016-10-05 20:04:56 +03:00
PatR
6fc21bfaa0 fix #H4492 - ing_suffix("throw") gave "throwwing"
The bug report assumed "you mime throwwing something" feedback
from 't-' was a typo, but 'throwwing' gets generated from 'throw'.
Change ing_suffix() not to double final 'w'.  Presumeably 'w' and 'y'
are exceptions because they're sometimes used as vowels.

Change 'strrchr()' to 'rindex()' like the rest of nethack.  Someday
those will need to be switched the other way around.

Add some missing bounds checking, although since ing_suffix() isn't
used for user-supplied strings, that's probably superfluous.
2016-08-23 19:37:42 -07:00
PatR
c4a9d6a45c newline handling
In light of the recent 'bad options' feedback issue where \r messed
up message display, try to to make newline handling be more consistent.
I'm sure there are lots of places that still handle \n manually, but
it's a start.
2015-12-25 21:54:01 -08:00
PatR
3ec592e3f1 fix bz60 and bz61 - meta char feedback
60: getpos() doesn't report the offending keystroke accurately when
rejecting M-something as a movement keystroke while moving the cursor;
61: typing M-N as a command keystroke produces
 |Unknown command 'M-
 |                 '.
where the '.' on the second line clobbers the top line of the map.

I can't reproduce the first one without extending the altmeta hack
[a run-time option to treat two char sequence ESC c as M-c] to getpos()
and nh_poskey(), which I've done for testing but am not including here.

I can't reproduce the second as it's described, but M-^J produces
 |Unknown command 'M-
 |'.--More--
and this fixes that, with a general fix that applies to any meta char.

The diffs include some cleanup/groundwork for maybe extending altmeta.
2015-12-15 03:22:39 -08:00
Pasi Kallinen
d195052796 Remove trailing whitespaces 2015-11-09 13:06:19 +02:00
PatR
68cb45c9fd str_end_is()
Move this small utility routine to hacklib.c where other such things
live and where it's feasible to find them if you need the functionality
elsewhere.
2015-10-31 17:13:26 -07:00
PatR
ad3af4efb2 hacklib.c formatting
hacklib.c took a beating in the reformatting, so clean it up.
A tweak to the anti-predictability hack in setrandom() is the only
change in the actual code.
2015-05-27 03:49:09 -07:00
Sean Hunt
1c081b1647 Remove stale version control lines. 2015-05-25 09:21:31 +09:00
Sean Hunt
97d6fade74 Reformat all C files.
I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
2015-05-09 13:43:16 -04:00
karnov
2a907f894e Version number increment 2015-05-06 22:04:27 -04:00
PatR
27d8b631cd isspace() usage
Replace most uses of isspace() with a simple test for ' ' after
processing the string buffer with mungspaces (which replaces tab
with space, converts instances of consecutive whitespace into a
single space, and removes leading and trailing spaces).  The uses
where this wasn't done now cast their argument to (uchar) so that
platforms with signed chars will never pass negative values to it.

I didn't mess with the menu coloring code (except for casts to the
isspace() argument); it almost certainly could benefit from using
mungspaces.  I did mess with the symset processing quite a bit,
and hope I haven't accidentally broken anything.  Default symbols
and DECgraphics symbols still parse and display ok, so the rest of
dat/symbols should be ok too.  I didn't test symbols in the user's
config file because I don't remember how that's supposed to work.
2015-04-25 02:11:13 -07:00
nhmall
e1155aca6f add an initializer 2015-04-17 00:46:54 -04:00
nhmall
f6bf9f9999 protect against bad dates
A recent fault on mingw32 revealed that faulty
code which passes a bad or out-of-range date
value could have game-fatal consequences.
Add some protection.
2015-04-17 00:31:22 -04:00
nhmall
d52c6a208d date verification 2015-04-17 00:12:53 -04:00
PatR
5974ae5700 new pmatch variations
Add pmatchi() to perform case-insensitive wildcard matching, and
pmatchz() which is also case-insensitive and ignores spaces, dashes,
and underscores like the type of matching done during wish parsing.
At the moment, neither is being used, although DEBUGFILES handling
uses pmatch and needs to be taught to distinguish between case-
sensitive and case-insensitive filenames so will eventually use
pmatchi when appropriate.
2015-04-11 19:39:59 -07:00
Pasi Kallinen
ddd7c9b690 Cast time_t into unsigned long 2015-04-10 19:47:17 +03:00
Pasi Kallinen
3ab441b1a1 Quick band-aid to prevent PRNG prediction
This is originally Derek's change from Spork, but sniping it
so we can mark this done for now, and can move on with the
nextversion.

Better solution is to use something like the ISAAC PRNG, which
cannot be predicted.
2015-04-06 09:30:39 +03:00
Pasi Kallinen
fa4dda377d Move isqrt into hacklib, other minor fixage 2015-04-01 16:38:56 +03:00
Pasi Kallinen
0a9248c7f1 Merge branch 'master' of https://rodney.nethack.org:20040/git/NHsource into paxed-new_lev_comp
Conflicts:
	doc/fixes35.0
	include/extern.h
	include/ntconf.h
	include/obj.h
	include/patchlevel.h
	src/dig.c
	src/do.c
	src/files.c
	src/fountain.c
	src/mklev.c
	src/objnam.c
	src/options.c
	src/potion.c
	src/rumors.c
	src/save.c
	src/topten.c
	src/trap.c
	src/wield.c
	sys/share/pcmain.c
	sys/unix/unixmain.c
	sys/winnt/Makefile.msc
	util/lev_main.c
	util/makedefs.c
2015-03-24 19:46:38 +02:00
Pasi Kallinen
c9df82fb42 Update hacklib func comment doc 2015-03-21 16:49:31 +02:00
Pasi Kallinen
2ec4ff0b8c Fix C343-108 (e- leaves prompt on screen)
You'll get "You mime eating something."
2015-03-20 19:25:24 +02:00
Pasi Kallinen
47bb9abace New level compiler: code changes 2015-03-17 18:52:42 +02:00
Pasi Kallinen
232d4e69bb Death talks in CAPITAL LETTERS 2015-03-17 18:47:29 +02:00
Sean Hunt
5fb3fea9c6 Remove experimental Unicode support.
This reverts commit 7f0f43e6f9 and some related
subsequent commits.

This compiles, but I have not done extensive testing.

Conflicts:
	include/config.h
	include/decl.h
	include/extern.h
	include/global.h
	include/tradstdc.h
	include/wintty.h
	src/drawing.c
	src/files.c
	src/hacklib.c
	src/mapglyph.c
	src/options.c
	sys/winnt/nttty.c
	win/tty/getline.c
	win/tty/topl.c
	win/tty/wintty.c
2015-03-17 18:46:45 +02:00
keni
25cd007c48 Bulk recovery of file CVS headers and addition of NHDT- headers. 2015-03-17 18:45:12 +02:00
Pasi Kallinen
3bbbb01c53 Death talks in CAPITAL LETTERS 2015-03-15 09:53:34 +02:00
Sean Hunt
a3faa93403 Remove experimental Unicode support.
This reverts commit 7f0f43e6f9 and some related
subsequent commits.

This compiles, but I have not done extensive testing.

Conflicts:
	include/config.h
	include/decl.h
	include/extern.h
	include/global.h
	include/tradstdc.h
	include/wintty.h
	src/drawing.c
	src/files.c
	src/hacklib.c
	src/mapglyph.c
	src/options.c
	sys/winnt/nttty.c
	win/tty/getline.c
	win/tty/topl.c
	win/tty/wintty.c
2015-02-27 19:34:29 -05:00
keni
03140969ee Bulk recovery of file CVS headers and addition of NHDT- headers. 2015-02-26 09:19:03 -05:00
keni
4eabcee787 Add RCS version lines 2009-05-06 10:50:32 +00:00