Commit Graph
69 Commits
Author SHA1 Message Date
Rene Kita edc602651c Fix OOB access due to multiple backspaces
Commit 419ca82d57 (Fix m17n backspace handling causes out-of-bounds
write in checkType) introduced an incomplete fix.

In function checkType we store the length of the previous multi-char
character in a buffer plens_buffer with pointer plens pointing to the
current position inside the buffer. When encountering a backspace plens
is set to the previous position without a bounds check. This will lead
to plens being out of bounds if we get more backspaces than we have
processed multi-char characters before.

If we are at the beginning of the buffer do not decrement and set plen
(the current length) to 0.

This also fixes GH Issue #270 [BUG] Out of bound read in Strnew_size ,
Str.c:61

If the above explanation does sound weird it's because I didn't fully
grok that function. :-)
2023-07-13 09:48:23 +02:00
Rene KitaandTatsuya Kinoshita 07bccf3e36 Exit with error if a new buffer can't be allocated
When building with gcc and -Wnull-dereference, -O3 and -flto we get a
lot of warnings about potential null dereferences. Exiting instead of
returning NULL solves all of it.

If we cannot alloc memory, there is not much to do - exiting is the
easiest option.
2023-01-05 20:03:14 +09:00
Rene Kita 4e23ee03ca Handle failed system calls
Introduce a separate TU for utility functions util.c. Add a function
exec_cmd to simplify execution of system commands with error handling.

While at it, suppress a warning about unused result when executing a
shell command. As we only display the command's output we do not care
about the exit code.

This fixes Debian bug #398989[0]

[0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=398989
2023-01-04 13:59:49 +01:00
Rene Kita 7c7af9e70c Move declarations to appropiate header files
This is in preparation for the next patch.
2023-01-04 13:59:49 +01:00
Rene Kita da9722e3b7 Check LESSOPEN to avoid undefined behaviour
Like less, w3m can use an input preprocessor when displaying files. The
preprocessor command is taken from the environment variable LESSOPEN.
The command line in LESSOPEN should include one occurrence of the string
"%s", which will be replaced by the filename when the input preprocessor
command is invoked. Giving more than one "%s" - or a any other
conversion specifier - will lead to undefined behaviour.

Add a check to make sure the command given has only one "%s".

This fixes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=991608
2023-01-04 13:59:13 +01:00
Rene Kita 8df395e7a2 Refactor lessopen_stream
Use early returns to spare a level of indentation.
2023-01-04 13:59:13 +01:00
Rene Kita c77029570d Merge history file if it was modified after start
w3m reads the history file on startup and writes it on exit. That means
if you open multiple instances of w3m, the history file will contain the
history of the last instance closed. All other history changes are lost.

Check if the modification time of the history file has changed before
writing. If it has changed read the history file from the disk into a
new history. Push the entries that are in the current history but not in
the history file into the new history and write the new history to disk.
2023-01-04 13:58:58 +01:00
Rene Kita e0c9a02784 Move declarations to the appropriate header file 2023-01-04 13:58:58 +01:00
Rene Kita 14c8274d16 Add comment to explain placement of the ifdef 2023-01-04 13:58:58 +01:00
Rene Kita f186e8331f Let loadHistory return an error code
This is in preparation for a following patch.
2023-01-04 13:58:58 +01:00
Rene Kita de813c322c Use 'goto fail' to remove code duplication 2023-01-04 13:58:58 +01:00
Rene Kita 047b448a3a Recognize link targets in dfn elements
This fixes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1018696
2023-01-04 13:58:40 +01:00
Rene Kita 900b3d7b41 Refactor html.c 2023-01-04 13:58:40 +01:00
Rene Kita ba68a3b3e6 Align in html.c 2023-01-04 13:58:40 +01:00
Rene Kita e8287f36b0 Skip soft hyphen when reading token
The soft hyphen should only appear if a word is broken at the hyphen
position. Filter it out.

Adjust the entity test files to reflect the new behaviour.

This fixes Issue #224 and Debian Bug #830173.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830173
Bug-Debian: https://github.com/tats/w3m/issues/224
2023-01-04 13:58:10 +01:00
Rene Kita 2692d22006 Fix generated HTML for entity test
- Remove stray elements: </td>
- Add missing elements: <tr></tr>
- Add link to show where to get qjs from
2023-01-04 13:58:10 +01:00
Rene Kita 7078c78443 Remove unused variable 2022-12-25 11:55:58 +01:00
Rene Kita a2ce4d8ace Remove a warning for bzero with GCC 12
GCC 12.2.0 on Arch reports:
.table.c: In function ???set_table_matrix0???:
.table.c:3536:5: error: ???__builtin_memset??? specified size between
18446744071562067969 and 18446744073709551615 exceeds maximum object
size 9223372036854775807 [-Werror=stringop-overflow=]
lto1: all warnings being treated as errors
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
child exited with value 1
make: *** [Makefile:132: w3m] Error 1
2022-12-25 11:55:58 +01:00
Rene Kita e6b8a4e250 Fix potential null pointer dereference
Found when compiling with '-O3 -flto'.
2022-12-25 11:55:58 +01:00
Rene Kita 9759579283 Don't error out on deprecated declaration warnings
The function `unsigned char *MD5(const unsigned char *d, size_t n,
unsigned char *md)` from OpenSSL is deprecated and therefore generates
lots of warnings in the build when compiling against OpenSSL 3.0.

Do not treat these warnings as errors, but keep the warning active. This
should be reverted once OpenSSL-3.0 support arrives.
2022-12-25 11:55:53 +01:00
Rene Kita 8f3fcecc43 Retry if loading of a file fails
This fixes GH issue #210, Debian BTS #537761[1] and obsoletes Debian
BTS #946440[2].

File names like 'a#a.html', 'b?b.html' or 'c%20.html' can not be opened
without using '-o argv_is_url=1' as the file name is interpreted as a
local URL.

If everything fails and argv_is_url is not set retry as a local file.

[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537761
[2]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=946440
2022-05-02 13:35:51 +02:00
Rene Kita a2bd584934 Use the comment character in Examples 2022-05-01 12:04:23 +02:00
Rene Kita b21b50b1dd Say what the comment character is 2022-05-01 12:04:23 +02:00
Rene Kita 4486ac99bc Add GitHub Action to build source when pushing
Let's at least ensure that the source builds without warnings.

The build image used, Ubuntu, spits out quite some warnings about
ignored return values. Use '-Wno-unused-result' for now.

The configure options are chosen to resemble the default Debian version.
2022-05-01 11:50:23 +02:00
Rene Kita 9192ed59db Add option to set directory for temporary files
With this patch applied the user can configure a directory to store
temporary/cache files. The history and cookies remain in RC_DIR.

I suppose the intent of writing the history to a temp file first is to
make the actual write an atomic operation. As rename() does not work
across mount points, we need to handle the temp file for the history
different to keep this behaviour.

Add a new type for the temp history file and handle this case different
when creating a temp file.
2022-05-01 11:50:09 +02:00
Rene Kita a3b9887113 Enable -Wnull-dereference by default 2022-04-19 10:08:54 +02:00
Rene Kita e8a41ecfcc Exit if we cannot allocate a new tab during start 2022-04-19 10:08:54 +02:00
Rene Kita e6998fc9a4 Fix potential null dereference 2022-04-19 10:08:54 +02:00
Rene Kita 80642d1fe7 Fix potential null dereference 2022-04-19 10:08:54 +02:00
Rene Kita a0b3c1b467 Fix potential null dereference 2022-04-19 10:08:54 +02:00
Rene Kita 9eaf044c02 Check return value of Str... functions
All these functions, StrmyUFgets, StrISgets, etc. can potentially return
NULL. Add a check for it.
2022-04-19 10:08:54 +02:00
Rene Kita d33a522936 Fix potential null pointer dereference 2022-04-19 10:08:54 +02:00
Rene Kita 1308f5efe5 Check for NULL before dereferencing the pointer
In case of an error the whole frame is freed, break out of the loop to
return early.
2022-04-19 10:08:54 +02:00
Rene Kita 9f5c311e45 Do not call fclose() on a NULL pointer
The if clause is true if cache is NULL. man 3 fclose says:

  The  behaviour  of  fclose() is undefined if the stream parameter is an
  illegal pointer, or is a descriptor already passed to a previous  invo‐
  cation of fclose().

Check if cache is NULL before calling fclose().
2022-04-19 10:08:54 +02:00
Rene Kita 1365cc1ecc Check for NULL before dereferencing a pointer
l is part of the exit condition of the while loop. If we exit the loop
because l is NULL, we cannot dereference it.
2022-04-19 10:08:54 +02:00
Rene Kita 6432709b80 Check for NULL before dereferencing a pointer
get_auth_param() returns NULL in case of error.
2022-04-19 10:08:54 +02:00
Rene Kita 22d1fb47ac Remove null pointer dereference
This if is only true if both strchr return NULL, making sure that *q is
a NULL dereference.

The intention was to remove trailing '>' (or '\t') from the message-id
(p) for add_news_message().

Adjust the condition.
2022-04-19 10:03:13 +02:00
Rene Kita beb07d24bc Fix a warning about an unused variable
*xi is only used if USE_IMLIB is defined, move the declaration inside
the #ifdef block.
2022-04-18 11:42:05 +02:00
Rene Kita 6d1a8d44e2 Cast away a warning
strlen() takes a char *, but p is a unsigned char *.
2022-04-18 11:42:05 +02:00
Rene Kita 9a2b86088c Fix broken anchor with link number at EOL
If, while adding the link number, we detect that we need to flush the
line, the anchor will be broken. When returning to the last breakpoint
only the link number will be removed, the internal anchor reference '<a
hseq=... >' remains on the flushed line.

Instead of adding the link number in a separate operation, check if we
just processed an anchor tag and prepend the current token with the link
number.
2022-04-17 16:04:41 +02:00
Rene Kita 97af1e481f Do not swallow errors from GCC
Without this patch posubst always exits with 0. This is a problem when
chaining commands.
2022-02-20 11:25:15 +01:00
Rene Kita d5817a26c7 Use strict and warnings in posubst 2022-02-20 11:25:15 +01:00
Rene Kita cb3118b389 Check for linux/fb.h when configuring 2022-02-20 11:17:27 +01:00
Rene Kita a0c8de3f3f Let configure fail if Perl is not in $PATH 2022-02-20 11:17:27 +01:00
Rene Kita 0d3416e0c2 Let configure fail if no terminal library is found 2022-02-20 11:17:26 +01:00
Rene Kita 72177529d2 Ignore autom4te cache directory 2022-02-20 11:17:26 +01:00
Rene Kita 5b33d9f239 Cast away a warning under OpenBSD 7.0 2022-02-20 11:14:54 +01:00
Rene Kita bf40283a80 Enable -Wall by default 2022-02-20 11:14:54 +01:00
Rene Kita 0073ec6daf Use unsigned int for image size
This removes a warning with -Wall.
2022-02-20 11:14:54 +01:00
Rene Kita cf2fd623fc Use cast to suppress warning 2022-02-20 11:14:54 +01:00
Rene Kita d3ea4b33f1 Initialize struct before use 2022-02-20 11:14:54 +01:00
Rene Kita c5c63a1a3d Fix a potential buffer overflow
When compiling with -Wformat-overflow=2 GCC reports:
  note: 'sprintf' output between 16 and 35 bytes into a destination of size 32
2022-02-20 11:14:54 +01:00
Rene Kita cf7058b56c Let base64_encode() take a char *
Throughout the whole code base only char * is passed, but a unsigned
char * is expected. This leads to several warnings.

Fix the interface and cast to unsigned char * internally to avoid any
changes to the behaviour.
2022-02-20 11:14:54 +01:00
Rene Kita 561f27f833 Explicitly cast to unsigned when passing to MD5() 2022-02-20 11:14:54 +01:00
Rene Kita b25abc595c Let strncpy write the null terminator 2022-02-20 11:14:53 +01:00
Rene Kita 0cd26b92cb Take the correct char type in growbuf_append()
This change removes all warnings (-Wall) from this function.
2022-02-20 11:14:53 +01:00
Rene Kita ab22479fb3 Fix warning for unused variable w/o MENU_SELECT 2022-02-20 11:14:53 +01:00
Rene Kita 4901408ea5 Fix warning for unused variable without USE_M17N 2022-02-20 11:14:53 +01:00
Rene Kita 916104b7f2 Remove unused variable 2022-02-20 11:14:53 +01:00
Rene Kita dad5cbe83b Use main(void) when not taking arguments 2022-02-20 11:14:53 +01:00
Rene Kita 84f724a590 Use standard conforming main() definition 2022-02-20 11:14:53 +01:00
Rene Kita 89295504fc Suppress two warnings when compiling with tcc
While there, add some comments to better understand the code flow in
localcgi_post().
2022-02-20 11:14:53 +01:00
Rene Kita f7601b4555 Move OPTS to end of CFLAGS
This allows the user to override default options.
2022-02-20 11:14:53 +01:00
Rene Kita ba29eb3fcf Check for end of string when parsing Gopher URLs
This fixes issue #199 reported by Kuang-che Wu.

A specially crafted Gopher URL (e.g. '<a href=gopher:R>') could lead to
an out-of-bounds read.

Problem here was, that 'p' was incremented twice without checking for
the end of the string.

The interesting question for me is: What does this 'if' actually check?
What is special here about the 'R'? I did not find anything related in
RFC 1436 or in RFC 4266.
2022-02-17 12:46:07 +01:00
Rene Kita 9874c87ad1 Do not use imlib2-config
imlib2-config was dropped by Imlib2:
https://git.enlightenment.org/legacy/imlib2.git/commit/?id=e9d84bd2163e6fab494b5ce5cc8830a54ff97765

The fixes issue #213.
2022-02-12 13:02:26 +01:00
Rene Kita 4d34f77a4b Ignore tokens that look like HTML, but are not
This patch fixes issue 200 'heap-buffer-overflow in
shiftAnchorPosition'.

Any input that looks like a tag, but isn't, should just be ignored. HTML
is parsed in a two staged process. Stage 1 inserts internal tags (like
<a hseq=...>). Stage 2 assumes these internal tags are valid input
inserted in the previous stage. If we don't throw away non-valid HTML
tags in stage 1 any website can inject tags that are interpreted as
internal ones. This leads to an out-of-bound read in this test case.

The 'hseq=-90' from the input ends as the value (89 actually) of
'a->hseq' in 'anchor.c:555'. Then 'hl->marks[a->hseq]' is out of bounds
as there are only 30 entries in this list.

This is the test input:
<table>0<br <>0<xmp>È«<div><inteRnal><input_alt fid=0><dl>0<dl>0<button value='">0000000000000000000000000000000000000000ÿ000'><A hseq=-90 href=>0<hR align=middle>
2022-02-12 12:37:06 +01:00
Rene Kita e9f5910f1f Ensure VLA size is at least one (again)
This is the same issue as commit 12c7b62a42 and should have been
included there.

'maxcol' can be -1 which results in a size of 0. The array is never
accessed with 'maxcol < 0', but zero length variable length arrays are
undefined behaviour.
2021-10-04 10:00:04 +02:00
Rene Kita cab914ef48 Fix manipulation of ASN1_STRING
Take the correct type from ASN1_STRING_get0_data() to fix a warning.
IA5Strings are ASCII, we do not need to care about signedness.

Since the pointer returned by ASN1_STRING_get0_data() points to internal
memory of the ASN1_STRING we are not allowed to manipulate the data.
Also it is not guaranteed that the data is null terminated. Copy the
data to our own buffer and make sure it is null terminated before using
it.
2021-09-13 10:04:49 +02:00
Rene Kita 12c7b62a42 Ensure VLA size is at least one
Compiling with GCC 10.2 with -fsanitize=address,undefined valgrind
and opening the 'opions panel' reports:
table.c:1632:8: runtime error: variable length array bound evaluates to non-positive value 0
table.c:1266:11: runtime error: variable length array bound evaluates to non-positive value 0
table.c:1267:12: runtime error: variable length array bound evaluates to non-positive value 0

'maxcell' is initialized to -1 which results in a size of 0 during the
first iteration. Though the array is only accessed if maxcell >= 0,
using a variable length array with a size < 1 is undefined behaviour
(see e.g. C99 6.7.5.2,p5).

This closes issue #51 .
2021-09-02 10:32:44 +02:00