Discussion:
[PATCH] sm3: support to compile with libgcrypt
Add Reply
Jia Zhang
2017-10-29 04:14:58 UTC
Reply
Permalink
Raw Message
Hi Bruno,

I refreshed the patches based on the latest master branch.

Basically the problem we discussed may still exist. But anyway we have a
clear patch without the sm3 basis.

Changelog:

- fix the following 10 failures:
[gc-gnulib.c] 8 failures
lib/gc-gnulib.c: In function 'gc_init':
lib/gc-gnulib.c:87:1: error: function might be candidate for attribute
'const' [-Werror=suggest-attribute=const]
gc_init (void)
^~~~~~~
lib/gc-gnulib.c: In function 'gc_done':
lib/gc-gnulib.c:114:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-gnulib.c: In function 'gc_set_allocators':
lib/gc-gnulib.c:217:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_set_allocators (gc_malloc_t func_malloc,
^~~~~~~~~~~~~~~~~
lib/gc-gnulib.c: In function 'gc_cipher_setkey':
lib/gc-gnulib.c:334:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char
*key)
^~~~~~~~~~~~~~~~
lib/gc-gnulib.c: In function 'gc_cipher_setiv':
lib/gc-gnulib.c:398:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
^~~~~~~~~~~~~~~
lib/gc-gnulib.c: In function 'gc_cipher_encrypt_inline':
lib/gc-gnulib.c:452:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c: In function 'gc_cipher_decrypt_inline':
lib/gc-gnulib.c:522:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c: In function 'gc_hash_digest_length':
lib/gc-gnulib.c:706:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~

[gc-libgcrypt.c] 2 failures
lib/gc-libgcrypt.c: In function 'gc_done':
lib/gc-libgcrypt.c:66:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-libgcrypt.c: In function 'gc_hash_digest_length':
lib/gc-libgcrypt.c:368:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~


Thanks,
Jia
Bruno Haible
2017-10-29 08:24:48 UTC
Reply
Permalink
Raw Message
Hi Jia,
Post by Jia Zhang
I refreshed the patches based on the latest master branch.
Thanks.
Post by Jia Zhang
Basically the problem we discussed may still exist.
Yes it still exists. The testdir for 'crypto/gc-sm3' fails to compile for me,
whereas 'crypto/gc-sha1' works. The following fixes it for me:

diff --git a/modules/crypto/gc-sm3-tests b/modules/crypto/gc-sm3-tests
index 21488df..006f41f 100644
--- a/modules/crypto/gc-sm3-tests
+++ b/modules/crypto/gc-sm3-tests
@@ -8,4 +8,4 @@ configure.ac:
Makefile.am:
TESTS += test-gc-sm3
check_PROGRAMS += test-gc-sm3
-test_gc_sm3_LDADD = $(LDADD) @LIB_CRYPTO@ $(LIBGCRYPT_LIBS)
+test_gc_sm3_LDADD = $(LDADD) @LIB_CRYPTO@
diff --git a/tests/test-gc-sm3.c b/tests/test-gc-sm3.c
index 3e412c8..608725d 100644
--- a/tests/test-gc-sm3.c
+++ b/tests/test-gc-sm3.c
@@ -19,7 +19,6 @@

#include <stdio.h>
#include <string.h>
-#include <gcrypt.h>
#include "gc.h"

int

Rationale:
1) LIBGCRYPT_LIBS is nowhere defined, therefore always empty.
2) The module description modules/crypto/gc-sm3 states that the user of
this module must include "gc.h", nothing else.

I squashes these adjustments into your patch and pushed it. Thanks for
the major work!
Post by Jia Zhang
[gc-gnulib.c] 8 failures
lib/gc-gnulib.c:87:1: error: function might be candidate for attribute
'const' [-Werror=suggest-attribute=const]
gc_init (void)
^~~~~~~
lib/gc-gnulib.c:114:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-gnulib.c:217:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_set_allocators (gc_malloc_t func_malloc,
^~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:334:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char
*key)
^~~~~~~~~~~~~~~~
lib/gc-gnulib.c:398:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
^~~~~~~~~~~~~~~
lib/gc-gnulib.c:452:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:522:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:706:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~
[gc-libgcrypt.c] 2 failures
lib/gc-libgcrypt.c:66:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-libgcrypt.c:368:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~
No, this is wrong. As I tried to explain in the last mail, we must respect
the semantics of the 'const' attribute. As a rule of thumb,
- functions that take pointer arguments must not be declared 'const',
- functions that make side effects must not be declared 'const'.
In other words, 'const' functions are functions which only take immediate
arguments, only do computations of a result (no side effects), and include
no randomness.

So, only 'gc_hash_digest_length' is eligible.

Additionally, only the declaration (in the .h files) needs to be changed.
You don't need the it at the implementation.

I pushed a reduced version of your patch, that includes only this function.


2017-10-29 Jia Zhang <***@alibaba-inc.com>
Bruno Haible <***@clisp.org>

crypto/gc: fix build failure with -Werror=suggest-attribute=const
* lib/gc.h (gc_hash_digest_length): Mark with 'const' attribute.

diff --git a/lib/gc.h b/lib/gc.h
index e65ba49..00e29e1 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -136,7 +136,8 @@ extern Gc_rc gc_cipher_close (gc_cipher_handle handle);
extern Gc_rc gc_hash_open (Gc_hash hash, Gc_hash_mode mode,
gc_hash_handle *outhandle);
extern Gc_rc gc_hash_clone (gc_hash_handle handle, gc_hash_handle *outhandle);
-extern size_t gc_hash_digest_length (Gc_hash hash);
+extern size_t gc_hash_digest_length (Gc_hash hash)
+ _GL_ATTRIBUTE_CONST;
extern void gc_hash_hmac_setkey (gc_hash_handle handle,
size_t len, const char *key);
extern void gc_hash_write (gc_hash_handle handle,
Jia Zhang
2017-10-29 13:10:01 UTC
Reply
Permalink
Raw Message
Post by Bruno Haible
Hi Jia,
Post by Jia Zhang
I refreshed the patches based on the latest master branch.
Thanks.
Post by Jia Zhang
Basically the problem we discussed may still exist.
Yes it still exists. The testdir for 'crypto/gc-sm3' fails to compile for me,
diff --git a/modules/crypto/gc-sm3-tests b/modules/crypto/gc-sm3-tests
index 21488df..006f41f 100644
--- a/modules/crypto/gc-sm3-tests
+++ b/modules/crypto/gc-sm3-tests
TESTS += test-gc-sm3
check_PROGRAMS += test-gc-sm3
diff --git a/tests/test-gc-sm3.c b/tests/test-gc-sm3.c
index 3e412c8..608725d 100644
--- a/tests/test-gc-sm3.c
+++ b/tests/test-gc-sm3.c
@@ -19,7 +19,6 @@
#include <stdio.h>
#include <string.h>
-#include <gcrypt.h>
#include "gc.h"
int
1) LIBGCRYPT_LIBS is nowhere defined, therefore always empty.
2) The module description modules/crypto/gc-sm3 states that the user of
this module must include "gc.h", nothing else.
Yes. I'm wrong on adding them.
Post by Bruno Haible
I squashes these adjustments into your patch and pushed it. Thanks for
the major work!
I think I see the root cause.

"fatal error: gcrypt.h: No such file or directory" is resolved by your
fix. But I will still have a link failure with crypto/gc-sm3 and even
crypto/gc.

In order to reproduce this link failure, I need to have a latest
libgcrypt installed, and then configure gnulib in this way:

$ ./gnulib-tool --create-testdir --dir=testdir --single-configure
crypto/gc-sm3 // or crypto/gc
$ cd testdir
$ ./configure CPPFLAGS=-Wall // with gc-gnulib
or
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt> // with gc-libgcrypt
$ make

For gc-gnulib case, it is always built with a success because it doesn't
link with libgcrypt. Instead, the gc-libgcrypt case will require
libgcrypt, and we will see a link failure.

To fix this issue, I must specify *--libtool* with gnulib-tool. Here is
a working instructions to test crypto/gc-sm3 (and crypto/gc) for me:

$ ./gnulib-tool --create-testdir --libtool --dir=testdir
--single-configure crypto/gc-sm3
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt>
$ make

And using gc-gnulib is always fine with us:

$ ./gnulib-tool --create-testdir --libtool --dir=testdir
--single-configure crypto/gc-sm3
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt>
$ make

Therefore, I have succeeded to have sm3 and gc-sm3 fully working in
gnulib with or without libgcrypt.

Thank you very much! Without your great helps, I cannot make it.

Cheers,
Jia
Post by Bruno Haible
Post by Jia Zhang
[gc-gnulib.c] 8 failures
lib/gc-gnulib.c:87:1: error: function might be candidate for attribute
'const' [-Werror=suggest-attribute=const]
gc_init (void)
^~~~~~~
lib/gc-gnulib.c:114:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-gnulib.c:217:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_set_allocators (gc_malloc_t func_malloc,
^~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:334:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char
*key)
^~~~~~~~~~~~~~~~
lib/gc-gnulib.c:398:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
^~~~~~~~~~~~~~~
lib/gc-gnulib.c:452:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:522:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char
*data)
^~~~~~~~~~~~~~~~~~~~~~~~
lib/gc-gnulib.c:706:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~
[gc-libgcrypt.c] 2 failures
lib/gc-libgcrypt.c:66:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_done (void)
^~~~~~~
lib/gc-libgcrypt.c:368:1: error: function might be candidate for
attribute 'const' [-Werror=suggest-attribute=const]
gc_hash_digest_length (Gc_hash hash)
^~~~~~~~~~~~~~~~~~~~~
No, this is wrong. As I tried to explain in the last mail, we must respect
the semantics of the 'const' attribute. As a rule of thumb,
- functions that take pointer arguments must not be declared 'const',
- functions that make side effects must not be declared 'const'.
In other words, 'const' functions are functions which only take immediate
arguments, only do computations of a result (no side effects), and include
no randomness.
So, only 'gc_hash_digest_length' is eligible.
Additionally, only the declaration (in the .h files) needs to be changed.
You don't need the it at the implementation.
I pushed a reduced version of your patch, that includes only this function.
crypto/gc: fix build failure with -Werror=suggest-attribute=const
* lib/gc.h (gc_hash_digest_length): Mark with 'const' attribute.
diff --git a/lib/gc.h b/lib/gc.h
index e65ba49..00e29e1 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -136,7 +136,8 @@ extern Gc_rc gc_cipher_close (gc_cipher_handle handle);
extern Gc_rc gc_hash_open (Gc_hash hash, Gc_hash_mode mode,
gc_hash_handle *outhandle);
extern Gc_rc gc_hash_clone (gc_hash_handle handle, gc_hash_handle *outhandle);
-extern size_t gc_hash_digest_length (Gc_hash hash);
+extern size_t gc_hash_digest_length (Gc_hash hash)
+ _GL_ATTRIBUTE_CONST;
extern void gc_hash_hmac_setkey (gc_hash_handle handle,
size_t len, const char *key);
extern void gc_hash_write (gc_hash_handle handle,
Bruno Haible
2017-10-29 15:00:52 UTC
Reply
Permalink
Raw Message
Hi Jia,
Post by Jia Zhang
I will still have a link failure with crypto/gc-sm3 and even
crypto/gc.
In order to reproduce this link failure, I need to have a latest
$ ./gnulib-tool --create-testdir --dir=testdir --single-configure
crypto/gc-sm3 // or crypto/gc
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt> // with gc-libgcrypt
$ make
... the gc-libgcrypt case will require
libgcrypt, and we will see a link failure.
To fix this issue, I must specify *--libtool* with gnulib-tool.
In normal situations, you need libtool only for _creating_ shared
libraries, not for merely linking with shared libraries. And a
gnulib testdir does not create shared libraries.

What exactly was the link error about? Did it not find libgcrypt,
or did it not find a dependency of it (libgpg-error)?

Did you install the "latest libgcrypt" in system directories?
If yes, try running ldconfig.
If no, the AC_LIB_HAVE_LINKFLAGS macro may not work right for you.
- As a workaround, try using
CPPFLAGS="-I<path_to_libgcrypt>/include" LDFLAGS="-L<path_to_libgcrypt>/lib -Wl,-rpath,<path_to_libgcrypt>/lib"
- or maybe you are on a bi-arch system, and there is a mismatch
between 'lib' and lib64'. You can resolve this by placing a symlink
lib64 -> lib or lib -> lib64.

Bruno
Jia Zhang
2017-10-30 01:35:40 UTC
Reply
Permalink
Raw Message
Post by Bruno Haible
Hi Jia,
Post by Jia Zhang
I will still have a link failure with crypto/gc-sm3 and even
crypto/gc.
In order to reproduce this link failure, I need to have a latest
$ ./gnulib-tool --create-testdir --dir=testdir --single-configure
crypto/gc-sm3 // or crypto/gc
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt> // with gc-libgcrypt
$ make
... the gc-libgcrypt case will require
libgcrypt, and we will see a link failure.
To fix this issue, I must specify *--libtool* with gnulib-tool.
In normal situations, you need libtool only for _creating_ shared
libraries, not for merely linking with shared libraries. And a
gnulib testdir does not create shared libraries.
What exactly was the link error about? Did it not find libgcrypt,
or did it not find a dependency of it (libgpg-error)?
Did you install the "latest libgcrypt" in system directories?
I didn't install the latest libgcrypt in system directory. Instead, it
is at <path_to_libgcrypt>.

Here are the instructions to reproduce the link failure:

- ./gnulib-tool --create-testdir --dir=testdir --single-configure
crypto/gc // or gc-sha1, gc-sm3 ...
- ./configure --with-libgcrypt --with-libgcrypt-prefix=<path_to_libgcrypt>
- make

make all-recursive
make[1]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir'
Making all in gllib
make[2]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
rm -f limits.h-t limits.h && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
-e 's|@''INCLUDE_NEXT''@|include_next|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
-e 's|@''PRAGMA_COLUMNS''@||g' \
-e 's|@''NEXT_LIMITS_H''@|<limits.h>|g' \
< ./limits.in.h; \
} > limits.h-t && \
mv limits.h-t limits.h
rm -f stdint.h-t stdint.h && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
-e 's/@''HAVE_STDINT_H''@/1/g' \
-e 's|@''INCLUDE_NEXT''@|include_next|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
-e 's|@''PRAGMA_COLUMNS''@||g' \
-e 's|@''NEXT_STDINT_H''@|<stdint.h>|g' \
-e 's/@''HAVE_C99_STDINT_H''@/1/g' \
-e 's/@''HAVE_SYS_TYPES_H''@/1/g' \
-e 's/@''HAVE_INTTYPES_H''@/1/g' \
-e 's/@''HAVE_SYS_INTTYPES_H''@/0/g' \
-e 's/@''HAVE_SYS_BITYPES_H''@/0/g' \
-e 's/@''HAVE_WCHAR_H''@/1/g' \
-e 's/@''HAVE_LONG_LONG_INT''@/1/g' \
-e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/1/g' \
-e 's/@''APPLE_UNIVERSAL_BUILD''@/0/g' \
-e 's/@''BITSIZEOF_PTRDIFF_T''@//g' \
-e 's/@''PTRDIFF_T_SUFFIX''@//g' \
-e 's/@''BITSIZEOF_SIG_ATOMIC_T''@//g' \
-e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@//g' \
-e 's/@''SIG_ATOMIC_T_SUFFIX''@//g' \
-e 's/@''BITSIZEOF_SIZE_T''@//g' \
-e 's/@''SIZE_T_SUFFIX''@//g' \
-e 's/@''BITSIZEOF_WCHAR_T''@//g' \
-e 's/@''HAVE_SIGNED_WCHAR_T''@//g' \
-e 's/@''WCHAR_T_SUFFIX''@//g' \
-e 's/@''BITSIZEOF_WINT_T''@//g' \
-e 's/@''HAVE_SIGNED_WINT_T''@//g' \
-e 's/@''WINT_T_SUFFIX''@//g' \
-e 's/@''GNULIB_OVERRIDES_WINT_T''@/0/g' \
< ./stdint.in.h; \
} > stdint.h-t && \
mv stdint.h-t stdint.h
/bin/mkdir -p sys
rm -f sys/types.h-t sys/types.h && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
-e 's|@''INCLUDE_NEXT''@|include_next|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
-e 's|@''PRAGMA_COLUMNS''@||g' \
-e 's|@''NEXT_SYS_TYPES_H''@|<sys/types.h>|g' \
-e 's|@''WINDOWS_64_BIT_OFF_T''@|0|g' \
-e 's|@''WINDOWS_STAT_INODES''@|0|g' \
< ./sys_types.in.h; \
} > sys/types.h-t && \
mv sys/types.h-t sys/types.h
make all-recursive
make[3]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
make[4]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
gcc -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1
-I/home/qianyue/Documents/git/libgcrypt/install/include -g -O2 -MT
sha1.o -MD -MP -MF .deps/sha1.Tpo -c -o sha1.o sha1.c
mv -f .deps/sha1.Tpo .deps/sha1.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1
-I/home/qianyue/Documents/git/libgcrypt/install/include -g -O2 -MT
gc-libgcrypt.o -MD -MP -MF .deps/gc-libgcrypt.Tpo -c -o gc-libgcrypt.o
gc-libgcrypt.c
mv -f .deps/gc-libgcrypt.Tpo .deps/gc-libgcrypt.Po
rm -f libgnu.a
ar cr libgnu.a sha1.o gc-libgcrypt.o
ranlib libgnu.a
make[4]: Leaving directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
make[3]: Leaving directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
make[2]: Leaving directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib'
Making all in glm4
make[2]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/glm4'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/glm4'
Making all in gltests
make[2]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gltests'
rm -f inttypes.h-t inttypes.h && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's/@''HAVE_INTTYPES_H''@/1/g' \
-e 's|@''INCLUDE_NEXT''@|include_next|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
-e 's|@''PRAGMA_COLUMNS''@||g' \
-e 's|@''NEXT_INTTYPES_H''@|<inttypes.h>|g' \
-e 's/@''PRI_MACROS_BROKEN''@/0/g' \
-e 's/@''APPLE_UNIVERSAL_BUILD''@/0/g' \
-e 's/@''HAVE_LONG_LONG_INT''@/1/g' \
-e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/1/g' \
-e 's/@''PRIPTR_PREFIX''@/"l"/g' \
-e 's/@''GNULIB_IMAXABS''@/0/g' \
-e 's/@''GNULIB_IMAXDIV''@/0/g' \
-e 's/@''GNULIB_STRTOIMAX''@/0/g' \
-e 's/@''GNULIB_STRTOUMAX''@/0/g' \
-e 's/@''HAVE_DECL_IMAXABS''@/1/g' \
-e 's/@''HAVE_DECL_IMAXDIV''@/1/g' \
-e 's/@''HAVE_DECL_STRTOIMAX''@/1/g' \
-e 's/@''HAVE_DECL_STRTOUMAX''@/1/g' \
-e 's/@''REPLACE_STRTOIMAX''@/0/g' \
-e 's/@''REPLACE_STRTOUMAX''@/0/g' \
-e 's/@''INT32_MAX_LT_INTMAX_MAX''@/1/g' \
-e 's/@''INT64_MAX_EQ_LONG_MAX''@/1/g' \
-e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/1/g' \
-e 's/@''UINT64_MAX_EQ_ULONG_MAX''@/1/g' \
-e '/definitions of _GL_FUNCDECL_RPL/r ./c++defs.h' \
-e '/definition of _GL_ARG_NONNULL/r ./arg-nonnull.h' \
-e '/definition of _GL_WARN_ON_USE/r ./warn-on-use.h' \
< ./inttypes.in.h; \
} > inttypes.h-t && \
mv inttypes.h-t inttypes.h
rm -f wchar.h-t wchar.h && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
-e 's|@''INCLUDE_NEXT''@|include_next|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
-e 's|@''PRAGMA_COLUMNS''@||g' \
-e 's|@''HAVE_FEATURES_H''@|1|g' \
-e 's|@''NEXT_WCHAR_H''@|<wchar.h>|g' \
-e 's|@''HAVE_WCHAR_H''@|1|g' \
-e 's/@''HAVE_CRTDEFS_H''@/0/g' \
-e 's/@''GNULIB_OVERRIDES_WINT_T''@/0/g' \
-e 's/@''GNULIB_BTOWC''@/0/g' \
-e 's/@''GNULIB_WCTOB''@/0/g' \
-e 's/@''GNULIB_MBSINIT''@/0/g' \
-e 's/@''GNULIB_MBRTOWC''@/0/g' \
-e 's/@''GNULIB_MBRLEN''@/0/g' \
-e 's/@''GNULIB_MBSRTOWCS''@/0/g' \
-e 's/@''GNULIB_MBSNRTOWCS''@/0/g' \
-e 's/@''GNULIB_WCRTOMB''@/0/g' \
-e 's/@''GNULIB_WCSRTOMBS''@/0/g' \
-e 's/@''GNULIB_WCSNRTOMBS''@/0/g' \
-e 's/@''GNULIB_WCWIDTH''@/0/g' \
-e 's/@''GNULIB_WMEMCHR''@/0/g' \
-e 's/@''GNULIB_WMEMCMP''@/0/g' \
-e 's/@''GNULIB_WMEMCPY''@/0/g' \
-e 's/@''GNULIB_WMEMMOVE''@/0/g' \
-e 's/@''GNULIB_WMEMSET''@/0/g' \
-e 's/@''GNULIB_WCSLEN''@/0/g' \
-e 's/@''GNULIB_WCSNLEN''@/0/g' \
-e 's/@''GNULIB_WCSCPY''@/0/g' \
-e 's/@''GNULIB_WCPCPY''@/0/g' \
-e 's/@''GNULIB_WCSNCPY''@/0/g' \
-e 's/@''GNULIB_WCPNCPY''@/0/g' \
-e 's/@''GNULIB_WCSCAT''@/0/g' \
-e 's/@''GNULIB_WCSNCAT''@/0/g' \
-e 's/@''GNULIB_WCSCMP''@/0/g' \
-e 's/@''GNULIB_WCSNCMP''@/0/g' \
-e 's/@''GNULIB_WCSCASECMP''@/0/g' \
-e 's/@''GNULIB_WCSNCASECMP''@/0/g' \
-e 's/@''GNULIB_WCSCOLL''@/0/g' \
-e 's/@''GNULIB_WCSXFRM''@/0/g' \
-e 's/@''GNULIB_WCSDUP''@/0/g' \
-e 's/@''GNULIB_WCSCHR''@/0/g' \
-e 's/@''GNULIB_WCSRCHR''@/0/g' \
-e 's/@''GNULIB_WCSCSPN''@/0/g' \
-e 's/@''GNULIB_WCSSPN''@/0/g' \
-e 's/@''GNULIB_WCSPBRK''@/0/g' \
-e 's/@''GNULIB_WCSSTR''@/0/g' \
-e 's/@''GNULIB_WCSTOK''@/0/g' \
-e 's/@''GNULIB_WCSWIDTH''@/0/g' \
-e 's/@''GNULIB_WCSFTIME''@/0/g' \
< ./wchar.in.h | \
sed -e 's|@''HAVE_WINT_T''@|1|g' \
-e 's|@''HAVE_BTOWC''@|1|g' \
-e 's|@''HAVE_MBSINIT''@|1|g' \
-e 's|@''HAVE_MBRTOWC''@|1|g' \
-e 's|@''HAVE_MBRLEN''@|1|g' \
-e 's|@''HAVE_MBSRTOWCS''@|1|g' \
-e 's|@''HAVE_MBSNRTOWCS''@|1|g' \
-e 's|@''HAVE_WCRTOMB''@|1|g' \
-e 's|@''HAVE_WCSRTOMBS''@|1|g' \
-e 's|@''HAVE_WCSNRTOMBS''@|1|g' \
-e 's|@''HAVE_WMEMCHR''@|1|g' \
-e 's|@''HAVE_WMEMCMP''@|1|g' \
-e 's|@''HAVE_WMEMCPY''@|1|g' \
-e 's|@''HAVE_WMEMMOVE''@|1|g' \
-e 's|@''HAVE_WMEMSET''@|1|g' \
-e 's|@''HAVE_WCSLEN''@|1|g' \
-e 's|@''HAVE_WCSNLEN''@|1|g' \
-e 's|@''HAVE_WCSCPY''@|1|g' \
-e 's|@''HAVE_WCPCPY''@|1|g' \
-e 's|@''HAVE_WCSNCPY''@|1|g' \
-e 's|@''HAVE_WCPNCPY''@|1|g' \
-e 's|@''HAVE_WCSCAT''@|1|g' \
-e 's|@''HAVE_WCSNCAT''@|1|g' \
-e 's|@''HAVE_WCSCMP''@|1|g' \
-e 's|@''HAVE_WCSNCMP''@|1|g' \
-e 's|@''HAVE_WCSCASECMP''@|1|g' \
-e 's|@''HAVE_WCSNCASECMP''@|1|g' \
-e 's|@''HAVE_WCSCOLL''@|1|g' \
-e 's|@''HAVE_WCSXFRM''@|1|g' \
-e 's|@''HAVE_WCSDUP''@|1|g' \
-e 's|@''HAVE_WCSCHR''@|1|g' \
-e 's|@''HAVE_WCSRCHR''@|1|g' \
-e 's|@''HAVE_WCSCSPN''@|1|g' \
-e 's|@''HAVE_WCSSPN''@|1|g' \
-e 's|@''HAVE_WCSPBRK''@|1|g' \
-e 's|@''HAVE_WCSSTR''@|1|g' \
-e 's|@''HAVE_WCSTOK''@|1|g' \
-e 's|@''HAVE_WCSWIDTH''@|1|g' \
-e 's|@''HAVE_WCSFTIME''@|1|g' \
-e 's|@''HAVE_DECL_WCTOB''@|1|g' \
-e 's|@''HAVE_DECL_WCWIDTH''@|1|g' \
| \
sed -e 's|@''REPLACE_MBSTATE_T''@|0|g' \
-e 's|@''REPLACE_BTOWC''@|0|g' \
-e 's|@''REPLACE_WCTOB''@|0|g' \
-e 's|@''REPLACE_MBSINIT''@|0|g' \
-e 's|@''REPLACE_MBRTOWC''@|0|g' \
-e 's|@''REPLACE_MBRLEN''@|0|g' \
-e 's|@''REPLACE_MBSRTOWCS''@|0|g' \
-e 's|@''REPLACE_MBSNRTOWCS''@|0|g' \
-e 's|@''REPLACE_WCRTOMB''@|0|g' \
-e 's|@''REPLACE_WCSRTOMBS''@|0|g' \
-e 's|@''REPLACE_WCSNRTOMBS''@|0|g' \
-e 's|@''REPLACE_WCWIDTH''@|0|g' \
-e 's|@''REPLACE_WCSWIDTH''@|0|g' \
-e 's|@''REPLACE_WCSFTIME''@|0|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r ./c++defs.h' \
-e '/definition of _GL_ARG_NONNULL/r ./arg-nonnull.h' \
-e '/definition of _GL_WARN_ON_USE/r ./warn-on-use.h'; \
} > wchar.h-t && \
mv wchar.h-t wchar.h
make all-recursive
make[3]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gltests'
Making all in .
make[4]: Entering directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gltests'
gcc -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib
-I/home/qianyue/Documents/git/libgcrypt/install/include -g -O2 -MT
dummy.o -MD -MP -MF .deps/dummy.Tpo -c -o dummy.o dummy.c
mv -f .deps/dummy.Tpo .deps/dummy.Po
rm -f libtests.a
ar cr libtests.a dummy.o
ranlib libtests.a
gcc -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib
-I/home/qianyue/Documents/git/libgcrypt/install/include -g -O2 -MT
test-gc-sha1.o -MD -MP -MF .deps/test-gc-sha1.Tpo -c -o test-gc-sha1.o
test-gc-sha1.c
mv -f .deps/test-gc-sha1.Tpo .deps/test-gc-sha1.Po
gcc -g -O2 -o test-gc-sha1 test-gc-sha1.o libtests.a
../gllib/libgnu.a libtests.a
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_init':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:48:
undefined reference to `gcry_control'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:51:
undefined reference to `gcry_control'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:54:
undefined reference to `gcry_check_version'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:57:
undefined reference to `gcry_control'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_open':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:182:
undefined reference to `gcry_cipher_open'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_setkey':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:195:
undefined reference to `gcry_cipher_setkey'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_setiv':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:207:
undefined reference to `gcry_cipher_setiv'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_encrypt_inline':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:217:
undefined reference to `gcry_cipher_encrypt'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_decrypt_inline':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:227:
undefined reference to `gcry_cipher_decrypt'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_cipher_close':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:237:
undefined reference to `gcry_cipher_close'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_open':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:331:
undefined reference to `gcry_md_open'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_clone':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:357:
undefined reference to `gcry_md_copy'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_read':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:459:
undefined reference to `gcry_md_ctl'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_close':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:474:
undefined reference to `gcry_md_close'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_buffer':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:551:
undefined reference to `gcry_md_hash_buffer'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_sha1':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:635:
undefined reference to `gcry_md_get_algo_dlen'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:642:
undefined reference to `gcry_md_open'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:646:
undefined reference to `gcry_md_write'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:648:
undefined reference to `gcry_md_read'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:657:
undefined reference to `gcry_md_close'
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:651:
undefined reference to `gcry_md_close'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_set_allocators':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:106:
undefined reference to `gcry_set_allocation_handler'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_hmac_setkey':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:428:
undefined reference to `gcry_md_setkey'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_write':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:441:
undefined reference to `gcry_md_write'
../gllib/libgnu.a(gc-libgcrypt.o): In function `gc_hash_read':
/home/qianyue/Documents/git/coreutils/gnulib/testdir/gllib/gc-libgcrypt.c:460:
undefined reference to `gcry_md_read'
collect2: error: ld returned 1 exit status
Makefile:940: recipe for target 'test-gc-sha1' failed
make[4]: *** [test-gc-sha1] Error 1
make[4]: Leaving directory
'/home/qianyue/Documents/git/coreutils/gnulib/testdir/gltests'
Post by Bruno Haible
If yes, try running ldconfig.
If no, the AC_LIB_HAVE_LINKFLAGS macro may not work right for you.
- As a workaround, try using
CPPFLAGS="-I<path_to_libgcrypt>/include" LDFLAGS="-L<path_to_libgcrypt>/lib -Wl,-rpath,<path_to_libgcrypt>/lib"
- or maybe you are on a bi-arch system, and there is a mismatch
between 'lib' and lib64'. You can resolve this by placing a symlink
lib64 -> lib or lib -> lib64.
Yes this workaound is working to me with an additional -lgcrypt
specified in LDFLAGS.

So this sounds likes AC_LIB_HAVE_LINKFLAGS is not working for the case
where libgcrypt is not installed to a system location if --libtool is
absent?

Thanks,
Jia
Post by Bruno Haible
Bruno
Bruno Haible
2017-11-20 23:11:53 UTC
Reply
Permalink
Raw Message
The code in lib/gc-gnulib.c line 823
sm3_finish_ctx (&ctx->sm3Context, ctx->hash);
passes a buffer of size 20 to a function which writes 32 bytes into it.
Thus provoking a buffer overrun.

This should fix it.


2017-11-20 Bruno Haible <***@clisp.org>

crypto/gc-sm3: Fix buffer overrun.
* lib/gc-gnulib.c (MAX_DIGEST_SIZE): Bump to 32.
Reported by Coverity.

diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index f888cf5..62074b1 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -602,7 +602,7 @@ gc_cipher_close (gc_cipher_handle handle)

/* Hashes. */

-#define MAX_DIGEST_SIZE 20
+#define MAX_DIGEST_SIZE 32

typedef struct _gc_hash_ctx
{
Jia Zhang
2017-11-21 01:02:07 UTC
Reply
Permalink
Raw Message
Hi Bruno,

This fix looks good enough.

Thanks,
Jia
Post by Bruno Haible
The code in lib/gc-gnulib.c line 823
sm3_finish_ctx (&ctx->sm3Context, ctx->hash);
passes a buffer of size 20 to a function which writes 32 bytes into it.
Thus provoking a buffer overrun.
This should fix it.
crypto/gc-sm3: Fix buffer overrun.
* lib/gc-gnulib.c (MAX_DIGEST_SIZE): Bump to 32.
Reported by Coverity.
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index f888cf5..62074b1 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -602,7 +602,7 @@ gc_cipher_close (gc_cipher_handle handle)
/* Hashes. */
-#define MAX_DIGEST_SIZE 20
+#define MAX_DIGEST_SIZE 32
typedef struct _gc_hash_ctx
{
Loading...