Skip to contentSkip to conversation

mke2fs: Escape double quotes when parsing mke2fs.conf

PATCH Applied Lukas Czerner 3 participants 4 messages Nov 2, 2020 – Jan 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mke2fs: Escape double quotes when parsing mke2fs.conf

Currently, when constructing the <default> configuration pseudo-file using the profile-to-c.awk script we will just pass the double quotes as they appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either fail to compile because of syntax error, or leave the resulting configuration invalid.

It can be reproduced by adding the following line somewhere into mke2fs.conf configuration and forcing mke2fs to use the <default> configuration by specifying nonexistent mke2fs.conf

MKE2FS_CONFIG="nonexistent" ./misc/mke2fs -T ext4 /dev/device

default_mntopts = "acl,user_xattr"
^ this will fail to compile

default_mntopts = ""
^ this will result in invalid config file

Syntax error in mke2fs config file (<default>, line #4)
Unknown code prof 17

Fix it by escaping the double quotes with a backslash in profile-to-c.awk script.

---
 misc/profile-to-c.awk | 1 +
 1 file changed, 1 insertion(+)
misc/profile-to-c.awk +1 -0
index f964efd6..814f7236 100644
@@ -4,6 +4,7 @@ BEGIN {
 }
 
 {
+  gsub("\"","\\\"",$0);
   printf("  \"%s\\n\"\n", $0);
 }
 
Signature · 1 line
2.26.2
#1 lore raw
Quoted 18 lines · Lukas Czerner

Currently, when constructing the <default> configuration pseudo-file using the profile-to-c.awk script we will just pass the double quotes as they appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either fail to compile because of syntax error, or leave the resulting configuration invalid.

It can be reproduced by adding the following line somewhere into mke2fs.conf configuration and forcing mke2fs to use the <default> configuration by specifying nonexistent mke2fs.conf

MKE2FS_CONFIG="nonexistent" ./misc/mke2fs -T ext4 /dev/device

default_mntopts = "acl,user_xattr"
^ this will fail to compile

Quoted 8 lines

default_mntopts = ""
^ this will result in invalid config file

Syntax error in mke2fs config file (<default>, line #4)
Unknown code prof 17

Fix it by escaping the double quotes with a backslash in profile-to-c.awk script.

What about using single quotes for this? That avoids the need to escape the double quotes, and avoids significant issues (IMHO) when the number of escapes grows over time as they are swallowed by various levels of processing.

Cheers, Andreas

Quoted 19 lines

---
misc/profile-to-c.awk | 1 +

1 file changed, 1 insertion(+)
misc/profile-to-c.awk +1 -1
index f964efd6..814f7236 100644
@@ -4,6 +4,7 @@ BEGIN {
 }
 
 {
+  gsub("\"","\\\"",$0);
  printf("  \"%s\\n\"\n", $0);
 }
 
--
Quoted 2 lines

2.26.2

Cheers, Andreas

#2 lore raw
Quoted 25 lines · Andreas Dilger
Quoted 24 lines · Lukas Czerner

Currently, when constructing the <default> configuration pseudo-file using the profile-to-c.awk script we will just pass the double quotes as they appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either fail to compile because of syntax error, or leave the resulting configuration invalid.

It can be reproduced by adding the following line somewhere into mke2fs.conf configuration and forcing mke2fs to use the <default> configuration by specifying nonexistent mke2fs.conf

MKE2FS_CONFIG="nonexistent" ./misc/mke2fs -T ext4 /dev/device

default_mntopts = "acl,user_xattr"
^ this will fail to compile

default_mntopts = ""
^ this will result in invalid config file

Syntax error in mke2fs config file (<default>, line #4)
Unknown code prof 17

Quoted 7 lines
Quoted 2 lines

Fix it by escaping the double quotes with a backslash in profile-to-c.awk script.

What about using single quotes for this? That avoids the need to escape the double quotes, and avoids significant issues (IMHO) when the number of escapes grows over time as they are swallowed by various levels of processing.

Hi Andreas,

I am not sure I understand what issues you have in mind. The way I see it, the profile-to-c.awk is used just during compile time to generate a mke2fs_default_profile string and that's consumed by mke2fs in the case no external config file can be found. There is only one level, or am I missing something ?

Regardless it is possible to use a single quote by changing the code in parse_line(). However I don't think we can just stop supporting double quotes since that would technically change the mke2fs.conf format so it would not solve the problem.

Thanks
-Lukas

Quoted 32 lines

Cheers, Andreas

Quoted 19 lines

---
misc/profile-to-c.awk | 1 +

1 file changed, 1 insertion(+)
misc/profile-to-c.awk +1 -1
index f964efd6..814f7236 100644
@@ -4,6 +4,7 @@ BEGIN {
 }
 
 {
+  gsub("\"","\\\"",$0);
  printf("  \"%s\\n\"\n", $0);
 }
 
--
Quoted 2 lines

2.26.2

Cheers, Andreas

#3 lore raw
In reply to Lukas Czerner
Quoted 7 lines · Lukas Czerner

Currently, when constructing the <default> configuration pseudo-file using the profile-to-c.awk script we will just pass the double quotes as they appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either fail to compile because of syntax error, or leave the resulting configuration invalid.

Applied, thanks.

- Ted