19 Commits
Author SHA1 Message Date
Tobias Stoeckmann 883600748e Major overhaul of rootmenu's file handling.
This diff fixes a huge amount of issues that could be triggered by using
the old-fashioned configuration files, i.e menu.  They can be activated
by using a line like "/path/to/menu".  On most systems, this file will be
parsed with cpp and the result sent through a pipe to WindowMaker.

Anyway, in the code path, memory leaks and buffer overruns await. I have
tried to fix these parts, but in the end it is more or less a rewrite,
whereas I used WINGs whenever possible.

Difference to previous implementation, beside of bugfixes:
- You are free to use single quotes and double quotes in configuration
- Linewrapping is allowed for other pipe'd data, too
- In general, line reading is unified throughout that file

Bugfixes:
- Avoid buffer overrun on lines which have line wrappings, that will happen
  ALWAYS, because wtrimspace-usage was erroneously.
- Avoid memory leak, also happened through wtrimspace usage.
- Avoid buffer overrun in separateline if a line ending happens early.
- Actually handle ferror() instead of only feof(), that would result in
  endless spinning
- A line wrapping at the end of a file is an error.
2012-05-07 20:49:15 -03:00
Tobias Stoeckmann 9e2d1b3ecf Don't fail with assert() in string functions if both strings are NULL.
wstrconcat and wstrappend already support situations in which first OR
second string are NULL, but not if BOTH are NULL.  Fixed that.
2012-05-07 20:47:22 -03:00
Tobias Stoeckmann 33328d997e Avoid buffer overrun in parseMenuCommand.
In parseMenuCommand, title[300] might get filled with a string of length
300.  The string is copied with strcpy, therefore the size would have to be
301 or -- as I propose -- the fixed value 300 gets replaced with
"sizeof(title) - 1".  This shows also that the size 300 belongs to title
and it will already be replaced during compile-time into 299.
2012-05-07 20:45:13 -03:00
Tobias Stoeckmann 6bc550d91b Remove curly brackets
...as they were completely wrapped up by another pair of curly brackets.
2012-05-07 20:42:34 -03:00
Tobias Stoeckmann cbff60297e Easier code path in appIconMouseDown 2012-05-07 20:41:18 -03:00
Tobias Stoeckmann 971f611bad wstrdup cannot fail, therefore no need to check for NULL. 2012-05-07 20:40:14 -03:00
Tobias Stoeckmann 70d8ad515b Easier error path in wDockTrackWindowLaunch.
There is no need to allocate command if the very next line might
fail independently from comand, freeing that memory again in error path.
2012-05-07 20:37:48 -03:00
Tobias Stoeckmann b5df97db95 Removed unused "buffer" variables. 2012-05-07 20:36:58 -03:00
Tobias Stoeckmann 72546aab81 Get rid of NEW definition.
The NEW definition merely calls wmalloc now, therefore it is not needed
anymore.  Pointed out and requested by Carlos R. Mafra.
2012-05-07 20:36:10 -03:00
Tobias Stoeckmann cc30444dda No need to call memset after wmalloc
memset is the last function call in wmalloc, just before it returns the
newly allocated memory.  Therefore it is not needed to call it again
after wmalloc call.  Although I would prefer to switch wmalloc to a
calloc-based wcalloc function, the compatibility of WINGs for old apps
should be kept.
2012-05-04 18:41:01 -03:00
Tobias Stoeckmann e6e3e1aa49 Avoid memory leak on error path in constructMenu. 2012-05-04 18:39:21 -03:00
Tobias Stoeckmann 753f44c4b7 Fixed memory leak in wHideAll. 2012-05-04 18:39:21 -03:00
Tobias Stoeckmann 2755b1e45d Use proper (w)free functions for (w)malloced data. 2012-05-04 18:39:21 -03:00
Tobias Stoeckmann 975d4becf1 Fixed some typos. 2012-05-04 18:39:21 -03:00
Tobias Stoeckmann 1bcfb89cd1 Adjust OpenBSD-specific code to match OpenBSD-current
Also fix null pointer dereference by NOT calling strlen on a possible
null pointer.
2012-04-30 14:50:17 -03:00
Tobias Stoeckmann e83eeb15cc Include assert.h to avoid linker issues if -DDEBUG was not supplied. 2012-04-30 14:48:20 -03:00
Tobias Stoeckmann f25464c792 Avoid GNUism in Makefiles for *BSD support
Variable abs_srcdir will always point to proper source location.
With this patch, there is no need to call gmake on OpenBSD anymore.
2012-04-30 14:46:54 -03:00
Tobias Stoeckmann e522ca734d WINGs: Fix memory leak in wtokenfree()
wtokenfree() does not free the first entry of an array.
If count is 1 then

   while (--count)

will be

   while (0)

and the inner body of that while-loop will not be entered.
Therefore a memory leak happens every time wtokenfree() is called.

Retrieved-from: http://paldium.homeunix.org/tobias/wmaker/patches/

[crmafra: This patch, altough correct, breaks WPrefs.app, which will be
fixed by the next patch. ]
2009-08-22 20:40:27 +02:00
Tobias Stoeckmann 1db15a3543 Fix multiple errors in findfile.c
Problems:

1.

  During expansion of path, the resulting path can overflow the supplied
  area of PATH_MAX+2 (buffer as well as buffer2). A tampered environment
  variable can be used to modify program flow.

Proof:
      [note: wmaker has been compiled with propolice]
      $ export A="[tested with 4096x A]"
      $ GNUSTEP_USER_ROOT="\$A\$A/\$A/\$A/" wmaker --for-real
      *** stack smashing detected ***: wmaker terminated
      Aborted

2.

  Way too many functions handle a return value of NULL for wexpandpath
  improperly, resulting in segfaults (and maybe other problems). To
  prove the existance of these issues:

Proof:
      $ GNUSTEP_USER_ROOT=~nouser wmaker --for-real
      wmaker error: could not get password entry for user nouser: Success
      Segmentation fault

Solution:

     hard exit with error message about what is going on.

3.

  The improper parsing of environment variables can lead to expansion
  of path names that were not intended to be expanded.

     (a) If a string like "$(var" is found, Window Maker tries to expand "var"
     	 (environment variable) although the syntax is wrong.

Proof:

      $ export PROOF=foo
      $ GNUSTEP_USER_ROOT=/\$\(PROOF wmaker --for-real
      wmaker warning: could not find user GNUstep directory (/foo/Defaults/WindowMaker).

      (b) If the variable out of a) cannot be resolved, a closing bracket will be
      	  added.

Proof:

      $ unset PROOF
      $ GNUSTEP_USER_ROOT=/\$\(PROOF wmaker --for-real
      ./wmaker warning: could not find user GNUstep directory ($(PROOF)/Defaults/WindowMaker).

Author: Tobias Stoeckmann
Retrieved-from: http://paldium.homeunix.org/tobias/wmaker/
Submitted-by: Gilbert Ashley <amigo@ibiblio.org>
2009-08-21 12:13:12 +02:00