zsh-workers
 help / color / mirror / code / Atom feed
* infinite recursion when handling the "out of memory" state
@ 2016-01-25 15:02 Kamil Dudka
  2016-01-25 15:31 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Kamil Dudka @ 2016-01-25 15:02 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

If zsh is compiled with multibyte support, handling of the "out of memory" 
state does not work well in certain cases -- instead of printing the error 
message and exiting, zsh ends up in an infinite recursion and crashes due to 
stack overflow.

The memory allocation functions in mem.c use zerr() to print the fatal error 
messages.  However, zerr() calls zwarning() and transitively mb_niceformat(), 
which allocates heap memory (and may call zerr() on failure).

I see three options how to prevent the stack overflow in such cases:

1. avoid using zerr() to print "out of memory" error messages

2. implement zerr() such that it does not trigger heap memory allocation
(I am afraid this is not really possible)

3. introduce a flag that would prevent zerr() from recurring into itself

I have attached a reproducer script.  It works reliably if the zsh executable 
is linked statically.  Otherwise it may happen that the dynamic linker is more 
hungry on memory than zsh itself, which would hide the bug.

Originally reported at: https://bugzilla.redhat.com/1300958

Kamil

[-- Attachment #2: oom.zsh --]
[-- Type: application/x-shellscript, Size: 699 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-25 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-25 15:02 infinite recursion when handling the "out of memory" state Kamil Dudka
2016-01-25 15:31 ` Peter Stephenson
2016-01-25 17:01   ` Kamil Dudka

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).