Mailing List Archive

[PATCH libgpg-error] gpgrt-config: escape expr(1) operands
With FreeBSD's expr(1), gpgrt-config prints the following:

$ PKG_CONFIG_LIBDIR=src ./src/gpgrt-config --libs
expr: illegal option -- L
expr: usage: expr [-e] expression

-L -lgpg-error
$

This happens because FreeBSD expr(1) makes no lexical distinction
between arguments which may be operators and arguments which
may be operands. [1]

To fix that, parenthesize values that could start with "-", as
suggested in the man page.

1: https://www.freebsd.org/cgi/man.cgi?query=expr&sektion=&n=1
---
src/gpgrt-config | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Note: there are similar invocations of expr(1) in gpgrt-config which
potentially could cause the same problem. However, I didn't touch those
because wasn't able to trigger these errors.

diff --git a/src/gpgrt-config b/src/gpgrt-config
index 3a76869..23b5ac7 100755
--- a/src/gpgrt-config
+++ b/src/gpgrt-config
@@ -404,7 +404,7 @@ sysroot () {
_result="$_result${_result:+ }$_opt"
shift
_result="$_result $PKG_CONFIG_SYSROOT_DIR$1"
- elif expr "$1" : "^$_opt" >/dev/null; then
+ elif expr "\( $1 \)" : "^$_opt" >/dev/null; then
_result="$_result${_result:+ }$_opt$PKG_CONFIG_SYSROOT_DIR$(expr "$1" : "^$_opt\(.*\)")"
else
_result="$_result${_result:+ }$1"
--
2.19.1


_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel
Re: [PATCH libgpg-error] gpgrt-config: escape expr(1) operands [ In reply to ]
Roman Bogorodskiy <bogorodskiy@gmail.com> wrote:
> With FreeBSD's expr(1), gpgrt-config prints the following:
[...]
> This happens because FreeBSD expr(1) makes no lexical distinction
> between arguments which may be operators and arguments which
> may be operands. [1]
>
> To fix that, parenthesize values that could start with "-", as
> suggested in the man page.

Thank you.

> --- a/src/gpgrt-config
> +++ b/src/gpgrt-config
> @@ -404,7 +404,7 @@ sysroot () {
> _result="$_result${_result:+ }$_opt"
> shift
> _result="$_result $PKG_CONFIG_SYSROOT_DIR$1"
> - elif expr "$1" : "^$_opt" >/dev/null; then
> + elif expr "\( $1 \)" : "^$_opt" >/dev/null; then

Here, the expression is to match string of $1 against $_opt. IIUC,
while this fix indeed escapes $1, I'm afraid it changes the semantics.

I fix it in a different way, by adding "x" to the expression. I also
fix another portability problem of expr.
--

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel
Re: [PATCH libgpg-error] gpgrt-config: escape expr(1) operands [ In reply to ]
NIIBE Yutaka wrote:

> Roman Bogorodskiy <bogorodskiy@gmail.com> wrote:
> > With FreeBSD's expr(1), gpgrt-config prints the following:
> [...]
> > This happens because FreeBSD expr(1) makes no lexical distinction
> > between arguments which may be operators and arguments which
> > may be operands. [1]
> >
> > To fix that, parenthesize values that could start with "-", as
> > suggested in the man page.
>
> Thank you.
>
> > --- a/src/gpgrt-config
> > +++ b/src/gpgrt-config
> > @@ -404,7 +404,7 @@ sysroot () {
> > _result="$_result${_result:+ }$_opt"
> > shift
> > _result="$_result $PKG_CONFIG_SYSROOT_DIR$1"
> > - elif expr "$1" : "^$_opt" >/dev/null; then
> > + elif expr "\( $1 \)" : "^$_opt" >/dev/null; then
>
> Here, the expression is to match string of $1 against $_opt. IIUC,
> while this fix indeed escapes $1, I'm afraid it changes the semantics.
>
> I fix it in a different way, by adding "x" to the expression. I also
> fix another portability problem of expr.

Hi,

For some reason, it looks like this change was not included to 1.34,
which is strange, because I can see the commit[1] in the repo.

If I do something like that, I can see the old bits are still there:

$ curl -s https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.34.tar.bz2 | tar Ojxf - libgpg-error-1.34/src/gpgrt-config |egrep -n 'expr ("\$1|match)'
451: elif expr "$1" : "^$_opt" >/dev/null; then
452: _result="$_result${_result:+ }$_opt$PKG_CONFIG_SYSROOT_DIR$(expr "$1" : "^$_opt\(.*\)")"
571:elif expr match "$module_list" "=\|!=\|<\|>\|<=\|>=" >/dev/null; then
$

Am I missing something?

1: https://github.com/gpg/libgpg-error/commit/1d71dbb

Roman Bogorodskiy
Re: [PATCH libgpg-error] gpgrt-config: escape expr(1) operands [ In reply to ]
Hello,

Thanks again for your report.

Roman Bogorodskiy <bogorodskiy@gmail.com> wrote:
> For some reason, it looks like this change was not included to 1.34,
> which is strange, because I can see the commit[1] in the repo.

I confirmed that the release of 1.33 and 1.34 have wrong gpgrt-config.

This is because gpgrt-config was generated file (in terms of automake,
it was the one in bin_SCRIPTS), but changed to the one of
dist_bin_SCRIPTS, during the development of 1.33, and we did not remove
generated gpgrt-config in our build directory. We should have removed
the generated file in our build directory.

1.35 will fix this problem.
--

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel
Re: [PATCH libgpg-error] gpgrt-config: escape expr(1) operands [ In reply to ]
NIIBE Yutaka <gniibe@fsij.org> wrote:
> I confirmed that the release of 1.33 and 1.34 have wrong gpgrt-config.

To reproduce the error, here is a scenario. You can reproduce that the
old generated gpgrt-config is in the released tarball.

If your automake is diffent version to the one of author, you will see
minor differences of automake generated files. Also, po/*.po will have
different time stamps. If you stay in different timezone, your
generated ChangeLog date fields will be also different.

Except these differences, it is only the file gpgrt-config, which is
different.

Well, for reproducibility, it would be good to invoke
gitlog-to-changelog with European timezone in Makefile.

==========================
# Preparation
# (1) Insall tools needed (git, autoconf, automake, etc.)
# (2) Manually install gnupg/build-aux/gitlog-to-changelog to /usr/local/bin

$ mkdir build-libgpg-error

# Clone the libgpg-error package
$ git clone git://git.gnupg.org/libgpg-error.git
$ cd libgpg-error

# Go to the version which used to generate gpgrt-config
$ git checkout 1096ff7
# And build the tarballs
$ ./autogen.sh
$ cd ../build-libgpg-error
$ ../libgpg-error/configure --enable-maintainer-mode
$ make distcheck

# This produces files:
# libgpg-error-1.33-beta40.swdb
# libgpg-error-1.33-beta40.tar.bz2
# libgpg-error-1.33-beta40.tar.gz

# Some clean up (to recover po/*.po files)
$ cd ../libgpg-error
$ git reset --hard

# Then, go to the released version of 1.34
$ git checkout libgpg-error-1.34
# And build the tarballs, with same BUILD directory (not cleaned)
$ ./autogen.sh
$ cd ../build-libgpg-error
$ make distcheck

# This produces files:
# libgpg-error-1.34.swdb
# libgpg-error-1.34.tar.bz2
# libgpg-error-1.34.tar.gz

$ cd ../libgpg-error
$ git reset --hard
==========================

In libgpg-error-1.34.tar.bz2 or libgpg-error-1.34.tar.gz, we can see old
generated gpgrt-config.
--

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel