Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] sim: common: modernize gennltvals.sh
Date: Mon, 18 Jan 2021 12:52:40 -0500	[thread overview]
Message-ID: <YAXK6BHbohlUp0io@vapier> (raw)
In-Reply-To: <0674d2d0-2534-ac08-c83c-4330d090a1bc@polymtl.ca>

On 18 Jan 2021 12:19, Simon Marchi via Gdb-patches wrote:
> On 2021-01-18 12:13 p.m., Mike Frysinger wrote:
> > i had run shellcheck and the only warnings (about unquoted expansion)
> > i didn't think we worth fixing because of the limited scope of the
> > script.  the variable in question isn't accepting user input, it's
> > operating on fixed inputs, and if we restrict ourselves to POSIX
> > shell (which i think we do), then our options are limited, and imo
> > the alternatives make it harder to read/understand.
> 
> Even considering this, I think it's worth just quoting the variables
> and getting rid the warnings.  It's trivial, and it would make any
> future (more important) warning more apparent.

to be clear, it isn't a style issue, it's a correctness issue.
adding the quotes will break the script.

here's the warning:
  printf '#include <%s>\n' ${files}
                           ^------^ SC2086: Double quote to prevent globbing and word splitting.

this is because the code passes in multiple files to process as an arg:
  gentvals "" errno ... "errno.h sys/errno.h" ...

then we use it like:
  files=$4
...
  for f in ${files}; do
...
  printf '#include <%s>\n' ${files}

unquoted, we get:
#include <errno.h>
#include <sys/errno.h>

quoted, we get:
#include <errno.h sys/errno.h>

our options are limited with POSIX shell:
* use arrays ... POSIX shell only has one builtin array: the args.
  so we'd rework the func API to pass in multiple files, and we'd
  operate on $@ by shifting it and iterating.
* change the shell runtime env by disabling path expansion.  that
  would mitigate the path expansion (which doesn't happen here as
  we know the inputs are all alphanumeric/periods), but still would
  have word splitting because we want that.

shell is just a bad programming language.  but i think the tree
specifically constrains itself to it for portability.  i don't know
what, if any, policies we have about using any other language.
-mike

  reply	other threads:[~2021-01-18 17:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-17 10:10 Mike Frysinger via Gdb-patches
2021-01-17 10:36 ` [PATCH] sim: common: delete configure & Makefile Mike Frysinger via Gdb-patches
2021-01-18 10:01   ` Andrew Burgess
2021-01-18 10:00 ` [PATCH] sim: common: modernize gennltvals.sh Andrew Burgess
2021-01-18 17:09   ` Mike Frysinger via Gdb-patches
2021-01-18 14:04 ` Simon Marchi via Gdb-patches
2021-01-18 17:13   ` Mike Frysinger via Gdb-patches
2021-01-18 17:19     ` Simon Marchi via Gdb-patches
2021-01-18 17:52       ` Mike Frysinger via Gdb-patches [this message]
2021-01-18 18:08         ` Simon Marchi via Gdb-patches
2021-01-18 21:15           ` Mike Frysinger via Gdb-patches
2021-01-18 21:27             ` Simon Marchi via Gdb-patches
2021-01-20 19:51             ` Tom Tromey
2021-01-18 17:20 ` [PATCH v2] " Mike Frysinger via Gdb-patches

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=YAXK6BHbohlUp0io@vapier \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=vapier@gentoo.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox