]> source.dussan.org Git - rspamd.git/commitdiff
Rewrite preprocess script to avoid string literal limit in C
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Dec 2015 13:47:36 +0000 (13:47 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Dec 2015 13:47:36 +0000 (13:47 +0000)
src/rspamadm/lua_preprocess.pl

index 014db3a9819dab3544effc62c0866b2df1d43818..4a84689a4bda13eddf01a42ad1d4bf6d7b6dcd90 100644 (file)
@@ -15,9 +15,10 @@ sub quote_file {
             quote_file($inc, $out);
         }
         else {
-            s/\"/\\"/g;
-            s/^(.*)$/"$1\\n"/;
-            print $out $_;
+            s/(.)/'$1',/g; # split as 'c',
+            s/\'\\\'/\'\\\\'/g; # escape backslashes
+            s/\'\'\'/\'\\\'\'/g; # escape single quotes
+            print $out "$_'\\n',";
         }
     }
 }
@@ -35,12 +36,12 @@ foreach my $file (@files) {
 #ifndef ${definename}_GUARD_H
 #define ${definename}_GUARD_H
 
-static const char ${varname}\[\] = ""
+static const char ${varname}\[\] = {
 EOD
         quote_file($in, $out);
 
         print $out <<EOD;
-"";
+'\\0'};
 #endif
 EOD
     }