[geany/geany] 4eb820: Export: don't try to read past the document end

Colomban Wendling git-noreply at xxxxx
Wed Apr 9 16:05:38 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Wed, 09 Apr 2014 16:05:38 UTC
Commit:      4eb8205f5605e680f83ce062e7d03fcf2bc26c3e
             https://github.com/geany/geany/commit/4eb8205f5605e680f83ce062e7d03fcf2bc26c3e

Log Message:
-----------
Export: don't try to read past the document end

A faulty bound checking resulted in reading a byte past the document
end, which resulted in Scintilla returning byte 0 because the position
was invalid.  By adding this NUL byte to the string used to build the
body, the body was truncated after the last document byte (as C strings
are NUL-terminated), leading to any format structure after it to be
missing from the output.

This broke HTML and LaTeX export if the last line didn't end with a
newline, as the last line's style closing structure were missing.


Modified Paths:
--------------
    plugins/export.c

Modified: plugins/export.c
4 files changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -393,7 +393,7 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename,
 	/* read the document and write the LaTeX code */
 	body = g_string_new("");
 	doc_len = sci_get_length(sci);
-	for (i = 0; i <= doc_len; i++)
+	for (i = 0; i < doc_len; i++)
 	{
 		style = sci_get_style_at(sci, i);
 		c = sci_get_char_at(sci, i);
@@ -635,7 +635,7 @@ static void write_html_file(GeanyDocument *doc, const gchar *filename,
 	/* read the document and write the HTML body */
 	body = g_string_new("");
 	doc_len = sci_get_length(sci);
-	for (i = 0; i <= doc_len; i++)
+	for (i = 0; i < doc_len; i++)
 	{
 		style = sci_get_style_at(sci, i);
 		c = sci_get_char_at(sci, i);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list