summaryrefslogtreecommitdiff
path: root/arch-nspawn.in
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-09-26 22:57:07 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-09-26 22:57:07 -0400
commit6a87c26b84e5cab7f4a8ead8abd62e58b7ec7f6c (patch)
tree48ed64f8684891542feb17f0e79f127252a79f7e /arch-nspawn.in
parent67bcecbbe42c727936d825363fbd1e2173bab574 (diff)
arch-nspawn: limit the machine_name length to ${HOST_NAME_MAX:-64} chars.
The criteria for a valid name are: - is made of of alphanumerics, "_", ".", and "-" - is not emtpy - cannot end with "." - cannot contain ".." - the maximum length is HOST_NAME_MAX, as defined in <limits.h> The existing code takes care of all but the last of these. So, added code after the existing code to check the length of the string, and grab the longest possible substring from the end. I hard-coded our interpretation of HOST_NAME_MAX as 64--on Linux that has been the value since version 1.0 of the kernel... I don't think it will be changing any time soon, and since systemd is Linux-only, we don't have to worry about other kernels. But, just in case, I included a commented out version that uses cpp to get the value.
Diffstat (limited to 'arch-nspawn.in')
-rw-r--r--arch-nspawn.in6
1 files changed, 6 insertions, 0 deletions
diff --git a/arch-nspawn.in b/arch-nspawn.in
index bde77b6..7dcd8ca 100644
--- a/arch-nspawn.in
+++ b/arch-nspawn.in
@@ -96,6 +96,12 @@ eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf")
machine_name="${working_dir//[![:alnum:]_-]/-}"
machine_name="${machine_name#-}"
+#HOST_NAME_MAX="$(printf '%s\n' '#include <limits.h>' 'HOST_NAME_MAX'|cpp -|sed -n '$p')"
+HOST_NAME_MAX=64
+if [[ ${#machine_name} -gt "$HOST_NAME_MAX" ]]; then
+ machine_name="${machine_name:(-${HOST_NAME_MAX})}"
+ machine_name="${machine_name#-}"
+fi
exec ${CARCH:+setarch "$CARCH"} systemd-nspawn \
-D "$working_dir" \