Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8301197

Invalid/incorrect use of printf makes the build fail

XMLWordPrintable

      Reported by Osipov, Michael on build-dev: https://mail.openjdk.org/pipermail/build-dev/2023-January/037487.html

      Hi folks,

      this is the upstream report for this downstream bug [1]:
      It basically boils down to that printf is used in .m4 and .sh files, but not formatting with %s, but rather direct variable expansion:
      > printf "$foo\n"
      rather than
      > printf "%s\n" $foo

      In the downstream bug the following makes the build fail:
      > ./configure ... --with-vendor-bug-url='https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Ports%20%26%20Packages&component=Individual%20Port(s)&short_desc=java/${PORTNAME}${JDK_MAJOR_VERSION}%3A%20'

      since the value contains percent char and the printf statement uses $var instead of %s $var printf tries to interprete it.

      I see these invalid usages:
      > $ grep -r --include='*.sh' --include='*.m4' printf jdk* --color=force | grep -v % | grep --color=always \\$
      > jdk11u-dev/make/autoconf/help.m4: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Debug level: $DEBUG_LEVEL\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* HS debug level: $HOTSPOT_DEBUG_LEVEL\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* JVM variants: $JVM_VARIANTS\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "$variant: \'$JVM_FEATURES_FOR_VARIANT\' "
      > jdk11u-dev/make/autoconf/help.m4: printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Version string: $VERSION_STRING ($VERSION_SHORT)\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Boot JDK: $BOOT_JDK_VERSION (at $BOOT_JDK)\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Toolchain: $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* C Compiler: Version $CC_VERSION_NUMBER (at ${CC#"$FIXPATH "})\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* C++ Compiler: Version $CXX_VERSION_NUMBER (at ${CXX#"$FIXPATH "})\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Cores to use: $JOBS\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* Memory limit: $MEMORY_SIZE MB\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "* ccache status: $CCACHE_STATUS\n"
      > jdk11u-dev/make/autoconf/help.m4: printf "$FOUND_ALT_VARIABLES\n"
      > jdk11u-dev/test/jdk/java/lang/ProcessBuilder/InheritIO/InheritIO.sh: 'InheritIO$'${TEST_NAME} printf message > stdout.txt 2> stderr.txt
      > jdk11u-dev/test/jdk/java/lang/Thread/UncaughtExceptions.sh: printf "$name:\n"; cat "$got"
      > jdk17u-dev/make/autoconf/help.m4: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Name: $CONF_NAME\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Debug level: $DEBUG_LEVEL\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* HS debug level: $HOTSPOT_DEBUG_LEVEL\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* JVM variants: $JVM_VARIANTS\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "$variant: \'$JVM_FEATURES_FOR_VARIANT\' "
      > jdk17u-dev/make/autoconf/help.m4: printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Version string: $VERSION_STRING ($VERSION_SHORT)\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Boot JDK: $BOOT_JDK_VERSION (at $BOOT_JDK)\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Toolchain: $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* C Compiler: Version $CC_VERSION_NUMBER (at ${CC#"$FIXPATH "})\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* C++ Compiler: Version $CXX_VERSION_NUMBER (at ${CXX#"$FIXPATH "})\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Cores to use: $JOBS\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* Memory limit: $MEMORY_SIZE MB\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "* ccache status: $CCACHE_STATUS\n"
      > jdk17u-dev/make/autoconf/help.m4: printf "$FOUND_ALT_VARIABLES\n"
      > jdk17u-dev/test/micro/org/openjdk/bench/java/nio/genBuffers.sh: printf "}\n" >> $out
      > jdk20u/make/autoconf/help.m4: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk20u/make/autoconf/help.m4: printf "The original configure invocation was '$REAL_CONFIGURE_COMMAND_EXEC_SHORT $REAL_CONFIGURE_COMMAND_LINE'.\n"
      > jdk20u/make/autoconf/help.m4: printf "* Name: $CONF_NAME\n"
      > jdk20u/make/autoconf/help.m4: printf "* Debug level: $DEBUG_LEVEL\n"
      > jdk20u/make/autoconf/help.m4: printf "* HS debug level: $HOTSPOT_DEBUG_LEVEL\n"
      > jdk20u/make/autoconf/help.m4: printf "* JVM variants: $JVM_VARIANTS\n"
      > jdk20u/make/autoconf/help.m4: printf "$variant: \'$JVM_FEATURES_FOR_VARIANT\' "
      > jdk20u/make/autoconf/help.m4: printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
      > jdk20u/make/autoconf/help.m4: printf "* Version string: $VERSION_STRING ($VERSION_SHORT)\n"
      > jdk20u/make/autoconf/help.m4: printf "* Source date: $source_date_info\n"
      > jdk20u/make/autoconf/help.m4: printf "* Boot JDK: $BOOT_JDK_VERSION (at $BOOT_JDK)\n"
      > jdk20u/make/autoconf/help.m4: printf "* Toolchain: $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)\n"
      > jdk20u/make/autoconf/help.m4: printf "* Devkit: $DEVKIT_NAME ($DEVKIT_ROOT)\n"
      > jdk20u/make/autoconf/help.m4: printf "* Devkit: $DEVKIT_ROOT\n"
      > jdk20u/make/autoconf/help.m4: printf "* Sysroot: $SYSROOT\n"
      > jdk20u/make/autoconf/help.m4: printf "* C Compiler: Version $CC_VERSION_NUMBER (at ${CC#"$FIXPATH "})\n"
      > jdk20u/make/autoconf/help.m4: printf "* C++ Compiler: Version $CXX_VERSION_NUMBER (at ${CXX#"$FIXPATH "})\n"
      > jdk20u/make/autoconf/help.m4: printf "* Build jobs: $JOBS\n"
      > jdk20u/make/autoconf/help.m4: printf "* Memory limit: $MEMORY_SIZE MB\n"
      > jdk20u/make/autoconf/help.m4: printf "* ccache status: $CCACHE_STATUS\n"
      > jdk20u/make/autoconf/help.m4: printf "$FOUND_ALT_VARIABLES\n"
      > jdk20u/test/micro/org/openjdk/bench/java/nio/genBuffers.sh: printf "}\n" >> $out
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "$OUTPUT_ROOT\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Debug level: $DEBUG_LEVEL\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* JDK variant: $JDK_VARIANT\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* JVM variants: $with_jvm_variants\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Environment: $WINDOWS_ENV_VENDOR version $WINDOWS_ENV_VERSION (root at $WINDOWS_ENV_ROOT_PATH)\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Boot JDK: $BOOT_JDK_VERSION (at $BOOT_JDK)\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Toolchain: $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* C Compiler: Version $CC_VERSION_NUMBER (at $CC)\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* C++ Compiler: Version $CXX_VERSION_NUMBER (at $CXX)\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Cores to use: $JOBS\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* Memory limit: $MEMORY_SIZE MB\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "* ccache status: $CCACHE_STATUS\n"
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "$FOUND_ALT_VARIABLES\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "$OUTPUT_ROOT\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Debug level: $DEBUG_LEVEL\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* JDK variant: $JDK_VARIANT\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* JVM variants: $with_jvm_variants\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Environment: $WINDOWS_ENV_VENDOR version $WINDOWS_ENV_VERSION (root at $WINDOWS_ENV_ROOT_PATH)\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Boot JDK: $BOOT_JDK_VERSION (at $BOOT_JDK)\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Toolchain: $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* C Compiler: Version $CC_VERSION_NUMBER (at $CC)\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* C++ Compiler: Version $CXX_VERSION_NUMBER (at $CXX)\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Cores to use: $JOBS\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* Memory limit: $MEMORY_SIZE MB\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "* ccache status: $CCACHE_STATUS\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "$FOUND_ALT_VARIABLES\n"
      > jdk8u-dev/jdk/test/java/lang/ProcessBuilder/InheritIO/InheritIO.sh: 'InheritIO$'${TEST_NAME} printf message > stdout.txt 2> stderr.txt
      > jdk8u-dev/jdk/test/java/lang/Thread/UncaughtExceptions.sh: printf "$name:\n"; cat "$got"

      although not all of them are problematic, at least these need to be fixed:
      > jdk8u-dev/common/autoconf/generated-configure.sh: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"
      > jdk8u-dev/common/autoconf/help.m4: printf "using configure arguments '$CONFIGURE_COMMAND_LINE'.\n"

      and for other JDK versions as well. The fixes are trivial [2], [3].

      Can some committer please at least log a bug in JBS for this?

      Regards,

      Michael

      [1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267690
      [2] https://bz-attachments.freebsd.org/attachment.cgi?id=237999
      [3] https://bz-attachments.freebsd.org/attachment.cgi?id=238000

            Unassigned Unassigned
            erikj Erik Joelsson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: