diff mbox

[v2] purge-locales: Handle empty locale directories better

Message ID 1457470977.25961.147.camel@rtred1test09.kymeta.local
State Accepted
Commit bbe29b9896d5a6a3b10c999522bb0ac29e934b51
Headers show

Commit Message

Trent Piepho March 8, 2016, 9:02 p.m. UTC
If a locale directory is empty, shell code like "for langdir in
$$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
than not looping at all, which would obviously be the desired
behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
that transform the expression from "${langdir##*/}" to "*" to "list of
all files in buildroot root dir".  Which is most certainly not what
this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes
all available memory and crashes trying to search it.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Peter Korsgaard April 28, 2016, 9:48 p.m. UTC | #1
>>>>> "Trent" == Trent Piepho <tpiepho@kymetacorp.com> writes:

 > If a locale directory is empty, shell code like "for langdir in
 > $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
 > than not looping at all, which would obviously be the desired
 > behavior.

 > Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
 > that transform the expression from "${langdir##*/}" to "*" to "list of
 > all files in buildroot root dir".  Which is most certainly not what
 > this command was supposed to do.

 > If one of those files happens to be an 8GB flash image, grep consumes
 > all available memory and crashes trying to search it.

 > Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>

Committed, thanks.
diff mbox

Patch

diff --git a/Makefile b/Makefile
index f2822a2..44ded9d 100644
--- a/Makefile
+++ b/Makefile
@@ -581,7 +581,10 @@  define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			if [ -e "$${langdir}" ]; \
+			then \
+				grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			fi \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \