Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeChecker parse produces invalid HTML (Uncaught SyntaxError: "" literal not terminated before end of script) #3748

Closed
dilyanpalauzov opened this issue Sep 23, 2022 · 2 comments · Fixed by #3753

Comments

@dilyanpalauzov
Copy link
Contributor

Describe the bug
CodeChecker parse --export html produces, among others, this file: parser_html.zip

When loaded in firefox it reports on line 733: Uncaught SyntaxError: "" literal not terminated before end of script

Chromium reports on the same line “Uncaught SyntaxError: Invalid or unexpected token”.

CodeChecker version

[INFO 2022-09-23 12:35] - CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version                                 
---------------------------------------------------------------
Base package version | 6.20.0                                  
Package build date   | 2022-09-16T12:36                        
Git commit ID (hash) | 7d65d89c2a3fed84f395016d4c9815bab860d0b3
Git tag information  | 6.20                                    
---------------------------------------------------------------

[INFO 2022-09-23 12:35] - CodeChecker web version:
------------------------------------------------------------------------------
Kind                                | Version                                 
------------------------------------------------------------------------------
Base package version                | 6.20.0                                  
Package build date                  | 2022-09-16T12:36                        
Git commit ID (hash)                | 7d65d89c2a3fed84f395016d4c9815bab860d0b3
Git tag information                 | 6.20                                    
Server supported Thrift API version | 6.51                                    
Client Thrift API version           | 6.51                                    
------------------------------------------------------------------------------
@dilyanpalauzov
Copy link
Contributor Author

The source code https://github.com/cyrusimap/cyrus-imapd/blob/master/imap/http_caldav.c#L2200 contains:

buf_printf_markup(body, --level, \"</script>\");

Which is included in the generated HTML as:

      var data = {"files": {"/git/cyrus/cyrus-imapd/lib/util.c": {"id": "/git/cyrus/cyrus-imapd/lib/util.c", "filePath": "/git/cyrus/cy\rus-imapd/lib/util.c", "content": "/* util.c  … buf_appendcstr(body, \"//]]>\\n\");\n    \buf_printf_markup(body, --level, \"</script>\");\n   

The browsers report error on “733:145970”. Line 733, column 145970. Column 145970 is the < in </script> above.

When converting C-source files into HTML, the converter shall replace <, >, & with &lt;, gt;, &amp;.

@dilyanpalauzov
Copy link
Contributor Author

This HTML:

<!DOCTYPE html><htlm>
  <head>
  </head>
  <body>
    Hello,
  <script>
    var f = "<script>var a ='bcd'</script><noscript>XXX</noscript>";
    console.log(f);
  </script>
Peter!
</body>
</html>

is invalid in both Firefox (Error message «Uncaught SyntaxError: "" literal not terminated before end of script») and Chromium (error message «Uncaught SyntaxError: Invalid or unexpected token»).

When the C-input contains printf("</script>\n"); that input is literally inserted into var data=… by report.output.html, generating invalid HTML.

dilyanpalauzov added a commit to dilyanpalauzov/codechecker that referenced this issue Oct 4, 2022
dilyanpalauzov added a commit to dilyanpalauzov/codechecker that referenced this issue Oct 15, 2022
dilyanpalauzov added a commit to dilyanpalauzov/codechecker that referenced this issue Oct 15, 2022
dilyanpalauzov added a commit to dilyanpalauzov/codechecker that referenced this issue Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant