diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-01-21 22:04:37 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-01-21 22:04:37 +0000 |
commit | e5cdb84647b17427ed0f8afc77ab83af6f537ac0 (patch) | |
tree | a08a425cb3704fbc75143d09715c6815ed3ec6f6 /lib/format.lua | |
parent | 1a930fe2020e3d309f4716c4814d1dd8a92ee03c (diff) | |
download | acf-core-e5cdb84647b17427ed0f8afc77ab83af6f537ac0.tar.bz2 acf-core-e5cdb84647b17427ed0f8afc77ab83af6f537ac0.tar.xz |
Added escapespecialcharacters to format.lua to escape shell special characters. Reviewed all calls to io.popen and os.execute to escape special characters. Fixed file uploads in openssl and ipsectools with viewfunctions.lua. Tried to fix openssl renew when subject contains special characters, but not done yet.release-0.4.19
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1687 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/format.lua')
-rw-r--r-- | lib/format.lua | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/format.lua b/lib/format.lua index 6ef831a..331d112 100644 --- a/lib/format.lua +++ b/lib/format.lua @@ -13,8 +13,14 @@ function dostounix ( str ) return data end +-- Escape Lua magic characters function escapemagiccharacters ( str ) - return string.gsub(str, "[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1") + return (string.gsub(str or "", "[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")) +end + +-- Escape shell special characters +function escapespecialcharacters ( str ) + return (string.gsub(str or "", "[~`#%$&%*%(%)\\|%[%]{};\'\"<>/]", "\\%1")) end -- search and remove all blank and commented lines from a string or table of lines @@ -182,7 +188,7 @@ function string_to_table ( text, delimiter) end function md5sum_string ( str) - cmd = "/bin/echo -n " .. str .. "|/usr/bin/md5sum|cut -f 1 -d \" \" " + local cmd = "/bin/echo -n \"" .. format.escapespecialcharacters(str) .. "\"|/usr/bin/md5sum|cut -f 1 -d \" \" " f = io.popen(cmd) local checksum = {} for line in f:lines() do @@ -207,7 +213,7 @@ expand_bash_syntax_vars = function (str) for w in string.gmatch (str, "${[^}]*}" ) do local rvar = string.sub(w,3,-2) local rval = ( deref(rvar) or "nil" ) - str = string.gsub (str, w, rval) + str = string.gsub (str, w, escapespecialcharacters(rval)) end return (str) |