Skip to contentSkip to conversation

selinux-image: Fix RE error getting POL_TYPE

PATCH In review George McCollister 2 participants 2 messages Nov 5, 2015 – Nov 8, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-image: Fix RE error getting POL_TYPE

Change [:space:] to [[:space:]]. [:space:] is incorrect and is treated as a list of characters. Prior to this change having a policy of 'standard' resulted in POL_TYPE being set to 'tandard'.

Change the regular expression to match from the beginning of the line since correcting the [:space:] error causes the '# SELINUXTYPE= can take one of these values:' line to match.

---
 classes/selinux-image.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
classes/selinux-image.bbclass +1 -1
index 362ca5c..9303610 100644
@@ -1,5 +1,5 @@
 selinux_set_labels () {
-    POL_TYPE=$(sed -n -e "s&SELINUXTYPE[:space:]*=[:space:]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
+    POL_TYPE=$(sed -n -e "s&^SELINUXTYPE[[:space:]]*=[[:space:]]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
     setfiles -r ${IMAGE_ROOTFS} ${IMAGE_ROOTFS}/${sysconfdir}/selinux/${POL_TYPE}/contexts/files/file_contexts ${IMAGE_ROOTFS} || exit 1;
 }
 
Signature · 1 line
2.4.5
#1 lore raw
Quoted 3 lines · George McCollister

Change [:space:] to [[:space:]]. [:space:] is incorrect and is treated as a list of characters. Prior to this change having a policy of 'standard' resulted in POL_TYPE being set to 'tandard'.

Good catch.

Quoted 3 lines

Change the regular expression to match from the beginning of the line since correcting the [:space:] error causes the '# SELINUXTYPE= can take one of these values:' line to match.

You may want to add an additional [[:space:]]* between the '^' and 'SELINUXTYPE' to allow for valid whitespace but that's cosmetic. I'd say pull it either way.

Best,
Philip

Quoted 17 lines
---
 classes/selinux-image.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
classes/selinux-image.bbclass +1 -1
index 362ca5c..9303610 100644
@@ -1,5 +1,5 @@
 selinux_set_labels () {
-    POL_TYPE=$(sed -n -e "s&SELINUXTYPE[:space:]*=[:space:]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
+    POL_TYPE=$(sed -n -e "s&^SELINUXTYPE[[:space:]]*=[[:space:]]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
     setfiles -r ${IMAGE_ROOTFS} ${IMAGE_ROOTFS}/${sysconfdir}/selinux/${POL_TYPE}/contexts/files/file_contexts ${IMAGE_ROOTFS} || exit 1;
 }