Bug 707649 - ./pdf/pdf_sec.c:186:25: error: assignment to ‘char **’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
Summary: ./pdf/pdf_sec.c:186:25: error: assignment to ‘char **’ from incompatible poin...
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Build Process (show other bugs)
Version: 10.02.0
Hardware: PC All
: P2 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-07 18:02 UTC by Sam James
Modified: 2024-03-13 12:41 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
patch (523 bytes, patch)
2024-03-08 03:29 UTC, Alex Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-03-07 18:02:39 UTC
Hit this when packaging ghostscript-10.03.0 for Gentoo:
```
./pdf/pdf_sec.c: In function ‘apply_sasl’:                                                                                                                                               ./pdf/pdf_sec.c:186:25: error: assignment to ‘char **’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]                                                              186 |             NewPassword = Password;                                                                                                                                                    |                         ^                                                                                                                                                        ./pdf/pdf_sec.c:187:20: error: assignment to ‘int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]                                                               187 |             NewLen = Len;                                                                                                                                                              |                    ^                                                                                                                                                             make[2]: *** [pdf/pdf.mak:169: soobj/pdf_sec.o] Error 1
make[2]: Leaving directory '/var/tmp/portage/app-text/ghostscript-gpl-10.03.0/work/ghostscript-10.03.0'
make[2]: *** Waiting for unfinished jobs....
```

Both -Wincompatible-pointer-types and -Wint-conversion become errors by default in upcoming GCC 14.
Comment 1 Alex Cherepanov 2024-03-07 22:55:54 UTC
I cannot reproduce this on gcc 11.4.0 with -Wincompatible-pointer-types and -Wint-conversion flags added. In particular, pdf_sec.c compiles without warnings in v. 10.03.0 and the current development head.

What version of gcc are you using?
Can you compile the unmodified version of Ghostscript from https://www.ghostscript.com/releases/gsdnld.html ?
Comment 2 Sam James 2024-03-08 00:01:09 UTC
Yes, I just reproduced it with vanilla https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10030/ghostscript-10.03.0.tar.gz, then ./configure && make -j$(nproc).

```
gcc  -DHAVE_MKSTEMP -DHAVE_FILE64 -DHAVE_FSEEKO -DHAVE_MKSTEMP64 -DHAVE_FONTCONFIG -DHAVE_LIBIDN -DHAVE_SETLOCALE -DHAVE_SSE2 -DHAVE_DBUS -DHAVE_BSWAP32 -DHAVE_BYTESWAP_H -DHAVE_STRERROR -DHAVE_ISNAN -DHAVE_ISINF  -DHAVE_PREAD_PWRITE=1 -DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE -O2 -DNDEBUG -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_LIBDL=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -DHAVE_SNPRINTF  -DBUILD_PDF=1 -I./pdf  -DHAVE_RESTRICT=1  -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1    -DSHARE_JPX=0  -Wno-attributes -DOPJ_STATIC -DMUTEX_pthread=0  -DUSE_JPIP -DUSE_OPENJPEG_JP2 -DOPJ_HAVE_STDINT_H=1 -DOPJ_HAVE_INTTYPES_H=1  -DOPJ_HAVE_FSEEKO=1 -DOPJ_HAVE_MALLOC_H=1 -DOPJ_HAVE_ALIGNED_ALLOC=1  -DOPJ_HAVE_MEMALIGN=1 -DOPJ_HAVE_POSIX_MEMALIGN=1  -DPDF_INCLUDED -I./pdf -I./obj -I./pcl/pl -I./base -Isrc/lib -I./jpegxr -I./zlib -I./openjpeg/src/lib/openjp2 -I./jbig2dec -c ./pdf/pdf_sec.c -o ./obj/pdf_sec.o
./pdf/pdf_sec.c: In function ‘apply_sasl’:
./pdf/pdf_sec.c:186:25: error: assignment to ‘char **’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
  186 |             NewPassword = Password;
      |                         ^
./pdf/pdf_sec.c:187:20: error: assignment to ‘int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  187 |             NewLen = Len;
      |                    ^
make: *** [pdf/pdf.mak:169: obj/pdf_sec.o] Error 1
```

```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/14/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-14.0.9999/work/gcc-14.0.9999/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/14 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14 --disable-silent-rules --disable-dependency-tracking --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/14/python --enable-languages=c,c++,fortran,rust --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=yes,extra,rtl --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo Hardened 14.0.9999 p, commit 4d92f1b90d9a1f0bfc9280745bd6cfb2fd68a2e8' --with-gcc-major-version-only --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-cet --disable-systemtap --enable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd --with-isl --disable-isl-version-check --enable-default-pie --enable-host-pie --enable-host-bind-now --enable-default-ssp --disable-fixincludes --with-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240306 (experimental) 74e8cc28eda9b1d75588fcd4017a735911b9d2b4 (Gentoo Hardened 14.0.9999 p, commit 4d92f1b90d9a1f0bfc9280745bd6cfb2fd68a2e8)
```

It's bleeding edge GCC, but I would be quite surprised if it turns out to be to blame here.

Indeed, if I replace s/gcc/clang/ on the failing command line, I get:
```
$ clang -DHAVE_MKSTEMP -DHAVE_FILE64 -DHAVE_FSEEKO -DHAVE_MKSTEMP64 -DHAVE_FONTCONFIG -DHAVE_LIBIDN -DHAVE_SETLOCALE -DHAVE_SSE2 -DHAVE_DBUS -DHAVE_BSWAP32 -DHAVE_BYTESWAP_H -DHAVE_STRERROR -DHAVE_ISNAN -DHAVE_ISINF  -DHAVE_PREAD_PWRITE=1 -DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE -O2 -DNDEBUG -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_LIBDL=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -DHAVE_SNPRINTF  -DBUILD_PDF=1 -I./pdf  -DHAVE_RESTRICT=1  -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1    -DSHARE_JPX=0  -Wno-attributes -DOPJ_STATIC -DMUTEX_pthread=0  -DUSE_JPIP -DUSE_OPENJPEG_JP2 -DOPJ_HAVE_STDINT_H=1 -DOPJ_HAVE_INTTYPES_H=1  -DOPJ_HAVE_FSEEKO=1 -DOPJ_HAVE_MALLOC_H=1 -DOPJ_HAVE_ALIGNED_ALLOC=1  -DOPJ_HAVE_MEMALIGN=1 -DOPJ_HAVE_POSIX_MEMALIGN=1  -DPDF_INCLUDED -I./pdf -I./obj -I./pcl/pl -I./base -Isrc/lib -I./jpegxr -I./zlib -I./openjpeg/src/lib/openjp2 -I./jbig2dec -c ./pdf/pdf_sec.c -o ./obj/pdf_sec.o
In file included from ./pdf/pdf_sec.c:18:
In file included from ./pdf/pdf_stack.h:21:
In file included from ./pdf/pdf_int.h:19:
In file included from ./pdf/ghostpdf.h:21:
In file included from ./base/gxgstate.h:23:
In file included from ./base/gsrefct.h:23:
./base/std.h:212:9: warning: 'dprintf' macro redefined [-Wmacro-redefined]
  212 | #define dprintf(str)\
      |         ^
/usr/include/bits/stdio2.h:121:12: note: previous definition is here
  121 | #   define dprintf(fd, ...) \
      |            ^
./pdf/pdf_sec.c:186:25: warning: incompatible pointer types assigning to 'char **' from 'char *'; take the address with & [-Wincompatible-pointer-types]
  186 |             NewPassword = Password;
      |                         ^ ~~~~~~~~
      |                           &
./pdf/pdf_sec.c:187:20: error: incompatible integer to pointer conversion assigning to 'int *' from 'int'; take the address with & [-Wint-conversion]
  187 |             NewLen = Len;
      |                    ^ ~~~
      |                      &
2 warnings and 1 error generated.
```
Comment 3 Sam James 2024-03-08 00:03:01 UTC
I'm confused as to how you don't see the warning, actually...

There's clearly 'char *Password' and 'char **NewPassword' and an assignment between them. It's not indirect or anything.
Comment 4 Sam James 2024-03-08 00:09:31 UTC
I can also reproduce it with 'gcc-11 (Gentoo Hardened 11.4.1_p20240229 p12) 11.4.1 20240229'.
Comment 5 Alex Cherepanov 2024-03-08 03:29:42 UTC
Created attachment 25449 [details]
patch

Thank you for the catch. It looks like most developers (myself including) don't have GNU Libidn installed. So the affected code just does not compile. Otherwise the bug would have been fixed long ago.

The fix is trivial: just dereference the affected pointers.
Comment 6 Ken Sharp 2024-03-08 08:24:07 UTC
(In reply to Alex Cherepanov from comment #5)
> Created attachment 25449 [details]
> patch
> 
> Thank you for the catch. It looks like most developers (myself including)
> don't have GNU Libidn installed. So the affected code just does not compile.
> Otherwise the bug would have been fixed long ago.
> 
> The fix is trivial: just dereference the affected pointers.

I know that, I have a commit ready to do exactly that, and yes, none of us have libidn installed.
Comment 7 Ken Sharp 2024-03-12 11:25:56 UTC
Fixed in this commit 90cabe08422afdd16bac5dd9217602679d943045

Thanks for the report!
Comment 8 Sam James 2024-03-13 03:05:10 UTC
Thanks folks!
Comment 9 Michael Osipov 2024-03-13 12:41:38 UTC
Also reported with FreeBSD: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277667