THRIFT-1755 Comment parsing bug
authorJens Geyer <jensg@apache.org>
Mon, 16 Sep 2013 20:17:52 +0000 (22:17 +0200)
committerJens Geyer <jensg@apache.org>
Mon, 16 Sep 2013 20:17:52 +0000 (22:17 +0200)
Patch: Brian Brooks & Jens Geyer

compiler/cpp/src/main.cc
compiler/cpp/src/thriftl.ll

index 0cefa7e..54c23f5 100755 (executable)
@@ -517,8 +517,13 @@ char* clean_up_doctext(char* doctext) {
     docstring += '\n';
   }
 
-  assert(docstring.length() <= strlen(doctext));
-  strcpy(doctext, docstring.c_str());
+  //assert(docstring.length() <= strlen(doctext));  may happen, see THRIFT-1755
+  if(docstring.length() <= strlen(doctext)) {
+    strcpy(doctext, docstring.c_str());
+  } else {
+    free(doctext);  // too short
+    doctext = strdup(docstring.c_str());
+  }
   return doctext;
 }
 
index 8538652..96d61ec 100644 (file)
@@ -36,6 +36,7 @@
 #pragma GCC diagnostic ignored "-Wunused-function"
 #pragma GCC diagnostic ignored "-Wunused-label"
 
+#include <cassert>
 #include <string>
 #include <errno.h>
 #include <stdlib.h>
@@ -366,7 +367,9 @@ literal_begin (['\"])
   if (g_parse_mode == PROGRAM) {
     clear_doctext();
     g_doctext = strdup(yytext + 3);
-    g_doctext[strlen(g_doctext) - 2] = '\0';
+    assert(strlen(g_doctext) >= 2);
+    g_doctext[strlen(g_doctext) - 2] = ' ';
+    g_doctext[strlen(g_doctext) - 1] = '\0';
     g_doctext = clean_up_doctext(g_doctext);
     g_doctext_lineno = yylineno;
   }