Skip to contentSkip to conversation

package/lvm2: LC_ALL set to "C" locale before generating cmds

PATCH In review Jeremy Lyda via buildroot 2 participants 3 messages Jan 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/lvm2: LC_ALL set to "C" locale before generating cmds

From 8527acf5177dd17c0ffafcd1b331b25a51d7a705 Mon Sep 17 00:00:00 2001
From: Jeremy Lyda <[email protected]>
Date: Thu, 13 Jan 2022 12:14:01 -0500
Subject: [PATCH 1/1] package/lvm2: LC_ALL set to "C" locale before generating
cmds

---
 ...t-to-C-locale-before-generating-cmds.patch | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 package/lvm2/0001-LC_ALL-set-to-C-locale-before-generating-cmds.patch
package/lvm2/0001-LC_ALL-set-to-C-locale-before-generating-cmds.patch new file +35 -0
new file mode 100644
index 0000000000..d9c31cc3f1
@@ -0,0 +1,35 @@
+From 8742a873dc3a89095760152db62b827ddba8ca24 Mon Sep 17 00:00:00 2001
+From: Jeremy Lyda <[email protected]>
+Date: Thu, 13 Jan 2022 12:00:54 -0500
+Subject: [PATCH 1/1] LC_ALL set to "C" locale before generating cmds
+
+An assumption is made prior to generating the cmds.h header file that the
+LC_COLLATE locale setting is set to "C" -- this is not always the case. If the
+locale is set for example to "en_US.UTF8" then it will alter the way that
+underscores compare to letters and numbers such that underscores will be sorted
+after letters and numbers. LVM in our experience does not gracefully handle
+this erroneous sorting and results in a segmentation fault at some point in
+program execution. Setting LC_ALL to the "C" locale (specifically LC_COLLATE)
+ensures a correct, consistent command environment across various systems.
+
+Signed-off-by: Jeremy Lyda <[email protected]>
+---
+ tools/Makefile.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/Makefile.in b/tools/Makefile.in
+index ec546ca63..c8530915c 100644
+--- a/tools/Makefile.in
++++ b/tools/Makefile.in
+@@ -181,7 +181,7 @@ cmds.h: $(srcdir)/command-lines.in Makefile
+ 	( cat $(srcdir)/license.inc && \
+ 	  echo "/* Do not edit. This file is generated by the Makefile. */" && \
+ 	  echo "cmd(CMD_NONE, none)" && \
+-	  $(GREP) '^ID:' $(srcdir)/command-lines.in | LANG=C $(SORT) -u | $(AWK) '{print "cmd(" $$2 "_CMD, " $$2 ")"}' && \
++	  $(GREP) '^ID:' $(srcdir)/command-lines.in | LANG=C LC_ALL=C $(SORT) -u | $(AWK) '{print "cmd(" $$2 "_CMD, " $$2 ")"}' && \
+ 	  echo "cmd(CMD_COUNT, count)" \
+ 	) > $@
+ 
+-- 
+2.25.1
+
Signature · 1 line
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#1 lore raw

Hello Jeremy,

Quoted 1 line · On Thu, 13 Jan 2022 17:48:57 +0000 Jeremy Lyda via buildroot…

Thanks a lot for your patch. Did you submit this patch to the upstream lvm2 project?

Also, could you send the patch with "git send-email", so that it appears inline, and not as an attached file?

Thanks a lot!

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Hello Thomas,

Quoted 2 lines

Thanks a lot for your patch. Did you submit this patch to the upstream lvm2 project?

I have not yet gotten around to it, but I do intend on submitting it, yes.

Quoted 2 lines

Also, could you send the patch with "git send-email", so that it appears inline, and not as an attached file?

I am struggling to get git send-email to cooperate with our mail server, but I will attach an inline copy of the patch below:

From 8527acf5177dd17c0ffafcd1b331b25a51d7a705 Mon Sep 17 00:00:00 2001
From: Jeremy Lyda <[email protected]>
Date: Thu, 13 Jan 2022 12:14:01 -0500
Subject: [PATCH 1/1] package/lvm2: LC_ALL set to "C" locale before generating
cmds

---
 ...t-to-C-locale-before-generating-cmds.patch | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 package/lvm2/0001-LC_ALL-set-to-C-locale-before-generating-cmds.patch
package/lvm2/0001-LC_ALL-set-to-C-locale-before-generating-cmds.patch new file +35 -0
new file mode 100644
index 0000000000..d9c31cc3f1
@@ -0,0 +1,35 @@
+From 8742a873dc3a89095760152db62b827ddba8ca24 Mon Sep 17 00:00:00 2001
+From: Jeremy Lyda <[email protected]>
+Date: Thu, 13 Jan 2022 12:00:54 -0500
+Subject: [PATCH 1/1] LC_ALL set to "C" locale before generating cmds
+
+An assumption is made prior to generating the cmds.h header file that the
+LC_COLLATE locale setting is set to "C" -- this is not always the case. If the
+locale is set for example to "en_US.UTF8" then it will alter the way that
+underscores compare to letters and numbers such that underscores will be sorted
+after letters and numbers. LVM in our experience does not gracefully handle
+this erroneous sorting and results in a segmentation fault at some point in
+program execution. Setting LC_ALL to the "C" locale (specifically LC_COLLATE)
+ensures a correct, consistent command environment across various systems.
+
+Signed-off-by: Jeremy Lyda <[email protected]>
+---
+ tools/Makefile.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/Makefile.in b/tools/Makefile.in
+index ec546ca63..c8530915c 100644
+--- a/tools/Makefile.in
++++ b/tools/Makefile.in
+@@ -181,7 +181,7 @@ cmds.h: $(srcdir)/command-lines.in Makefile
+ 	( cat $(srcdir)/license.inc && \
+ 	  echo "/* Do not edit. This file is generated by the Makefile. */" && \
+ 	  echo "cmd(CMD_NONE, none)" && \
+-	  $(GREP) '^ID:' $(srcdir)/command-lines.in | LANG=C $(SORT) -u | $(AWK) '{print "cmd(" $$2 "_CMD, " $$2 ")"}' && \
++	  $(GREP) '^ID:' $(srcdir)/command-lines.in | LANG=C LC_ALL=C $(SORT) -u | $(AWK) '{print "cmd(" $$2 "_CMD, " $$2 ")"}' && \
+ 	  echo "cmd(CMD_COUNT, count)" \
+ 	) > $@
+ 
+-- 
+2.25.1
+
Signature · 5 lines
2.25.1
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot