zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Christopher Browne <cbbrowne@gmail.com>
Cc: rahul <rahul2012@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: Higher order functions in zsh (article link)
Date: Thu, 7 Mar 2013 14:08:42 -0500	[thread overview]
Message-ID: <20130307190842.GA67680@redoubt.spodhuis.org> (raw)
In-Reply-To: <CAFNqd5WwOHg3aed8OrbFdwfJ5cxemu6DzBOS5uxuDgGWH41HgQ@mail.gmail.com>

On 2013-03-07 at 11:59 -0500, Christopher Browne wrote:
> cbbrowne@cbbrowne /tmp/maptest> function map {
>     local func_name=$1
>     shift
>     for elem in $@; print -- $(eval $func_name "${elem}")
> }
> 
> But somewhat curiously that doesn't help :-(.

Why does this code have an eval in there?  It's:
 (1) breaking the f3 example
 (2) introducing a security flaw

Hint:  touch 'f4 `mkdir snert`'

This works fine:
----------------------------8< cut here >8------------------------------
function map {
	local func_name=$1
	shift
	for elem in "$@"; print -- $($func_name "${elem}") 
}
----------------------------8< cut here >8------------------------------

With the eval in there, with { map echo * } f3 loses the quotes and f4
just shows "f4" and creates a new sub-directory, snert.

Lose the eval and things work, no new security hole.

Oh, and you need to quote the $@ to "$@" if you want to preserve empty
elements -- whether you do or not depends on what you're mapping across,
but I tend to think "present but empty" is distinct from "not present".

-Phil


  reply	other threads:[~2013-03-07 19:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-07  5:25 rahul
2013-03-07 16:59 ` Christopher Browne
2013-03-07 19:08   ` Phil Pennock [this message]
2013-03-07 21:12     ` Oliver Kiddle
2013-03-08  8:40 ` Stephen Blott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130307190842.GA67680@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=cbbrowne@gmail.com \
    --cc=rahul2012@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).