From 561e79b059e0a06dea7bc216641626fdfad099fb Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Thu, 6 Jun 2002 00:09:52 -0500 Subject: [PATCH] kbuild: Enforce UTS limit, use LANG=C for date/time Patch by Keith Owens, ported to 2.5. If the length of $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) exceeds 64 characters it silently corrupts the utsname data, resulting in garbage for uname -r and problems running the kernel and modules. Abort if KERNELRELEASE is too long. Truncation is not good enough, it results in ambiguous /lib/modules/`uname -r` contents. Ensure that the date/time in uname are always in LANG=C. Users with other languages report that 8 bit values cause the boot messages to go haywire. --- Makefile | 6 ++++++ init/Makefile | 1 + scripts/mkcompile_h | 26 +++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index ba741667ec40..2c2a223cd185 100644 --- a/Makefile +++ b/Makefile @@ -298,7 +298,13 @@ include/linux/autoconf.h: .config # version.h changes when $(KERNELRELEASE) etc change, as defined in # this Makefile +uts_len := 64 + include/linux/version.h: Makefile + @if expr length "$(KERNELRELEASE)" \> $(uts_len) >/dev/null ; then \ + echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ + exit 1; \ + fi; @echo -n 'Generating $@' @(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \ echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \ diff --git a/init/Makefile b/init/Makefile index 455416572bac..c68a879dde8f 100644 --- a/init/Makefile +++ b/init/Makefile @@ -22,4 +22,5 @@ $(TOPDIR)/include/linux/compile.h: ../include/linux/compile.h ; # actual file if its content has changed. ../include/linux/compile.h: FORCE + @echo -n 'Generating $@' @../scripts/mkcompile_h $@ "$(ARCH)" "$(CONFIG_SMP)" "$(CC) $(CFLAGS)" diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h index e18fc4f263e3..6313db961724 100755 --- a/scripts/mkcompile_h +++ b/scripts/mkcompile_h @@ -10,24 +10,32 @@ else echo 0 > ../.version fi + +UTS_VERSION="#$VERSION" +if [ -n "$SMP" ] ; then UTS_VERSION="$UTS_VERSION SMP"; fi +UTS_VERSION="$UTS_VERSION `LANG=C date`" + +# Truncate to maximum length + +UTS_LEN=64 +UTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/" + # Generate a temporary compile.h ( echo /\* This file is auto generated, version $VERSION \*/ echo \#define UTS_MACHINE \"$ARCH\" - echo -n \#define UTS_VERSION \"\#$VERSION - if [ -n "$SMP" ] ; then echo -n " SMP"; fi - echo ' '`date`'"' + echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" - echo \#define LINUX_COMPILE_TIME \"`date +%T`\" + echo \#define LINUX_COMPILE_TIME \"`LANG=C date +%T`\" echo \#define LINUX_COMPILE_BY \"`whoami`\" - echo \#define LINUX_COMPILE_HOST \"`hostname`\" + echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" if [ -x /bin/dnsdomainname ]; then - echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname`\" + echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\" elif [ -x /bin/domainname ]; then - echo \#define LINUX_COMPILE_DOMAIN \"`domainname`\" + echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\" else echo \#define LINUX_COMPILE_DOMAIN fi @@ -48,10 +56,10 @@ if [ -r $TARGET ] && \ grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \ grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \ cmp -s .tmpver.1 .tmpver.2; then - echo $TARGET was not updated; + echo ' (unchanged)' rm -f .tmpcompile else - echo $TARGET was updated + echo ' (updated)' mv -f .tmpcompile $TARGET fi rm -f .tmpver.1 .tmpver.2 -- 2.39.5