Prevent Okular from crashing when synctex logs an error

bd20e48c3c updated Okular's copy of the synctex code to 1.19.
Unfortunately since this version the upstream code logs errors like
`"! SyncTeX Error : Ignored record...` when accessing selected synctex
files created with older versions of synctex.

The upstream `_synctex_log` contains `va_list arg` as a parameter, but
fails to initialize and tear down this properly via `va_start` and
`va_end`. In general this seems to work for the single argument case.
However, once we apply our hardening patch to get rid of the
`gnu_printf format attribute` warning and thus introduce a variadic
argument, things go wrong.

To fix this, we add the missing code. The remaining changes are just
refreshing the patches.

BUG: 383915

Test Plan:
Opening `empty.pdf` with `empty.synctex.gz` from
https://bugs.kde.org/attachment.cgi?id=109116 located
in the same folder does not lead to Okular segfaulting anymore.
This commit is contained in:
Henrik Fehlauer 2017-11-30 12:56:17 +01:00
parent b6573a2713
commit dccd83783d
6 changed files with 17 additions and 5 deletions

View file

@ -54,7 +54,7 @@ Index: synctex/synctex_parser_utils.c
===================================================================
--- synctex.orig/synctex_parser_utils.c
+++ synctex/synctex_parser_utils.c
@@ -87,7 +87,9 @@ void _synctex_free(void * ptr) {
@@ -87,8 +87,11 @@ void _synctex_free(void * ptr) {
# include <syslog.h>
#endif
@ -63,5 +63,15 @@ Index: synctex/synctex_parser_utils.c
+int _synctex_log(int level, const char * prompt, const char * reason, ...) {
+ va_list arg;
int result;
+ va_start(arg, reason);
# ifdef SYNCTEX_RECENT_WINDOWS
{/* This code is contributed by William Blum.
As it does not work on some older computers,
@@ -130,6 +133,7 @@ int _synctex_log(int level, const char *
result += vfprintf(where, reason, arg);
result += fprintf(where,"\n");
# endif
+ va_end(arg);
return result;
}

View file

@ -7,7 +7,7 @@ Index: synctex/synctex_parser_utils.c
===================================================================
--- synctex.orig/synctex_parser_utils.c
+++ synctex/synctex_parser_utils.c
@@ -103,8 +103,26 @@ int _synctex_log(int level, const char *
@@ -104,8 +104,26 @@ int _synctex_log(int level, const char *
char *buff;
size_t len;
OutputDebugStringA(prompt);

View file

@ -27,7 +27,7 @@ Index: synctex/synctex_parser_utils.c
===================================================================
--- synctex.orig/synctex_parser_utils.c
+++ synctex/synctex_parser_utils.c
@@ -585,6 +585,6 @@ int _synctex_get_name(const char * outpu
@@ -587,6 +587,6 @@ int _synctex_get_name(const char * outpu
const char * _synctex_get_io_mode_name(synctex_io_mode_t io_mode) {
static const char * synctex_io_modes[4] = {"r","rb","a","ab"};

View file

@ -6,7 +6,7 @@ Index: synctex/synctex_parser_utils.c
===================================================================
--- synctex.orig/synctex_parser_utils.c
+++ synctex/synctex_parser_utils.c
@@ -408,7 +408,7 @@ char * _synctex_merge_strings(const char
@@ -410,7 +410,7 @@ char * _synctex_merge_strings(const char
/* The purpose of _synctex_get_name is to find the name of the synctex file.
* There is a list of possible filenames from which we return the most recent one and try to remove all the others.

View file

@ -315,7 +315,7 @@ Index: synctex/synctex_parser_utils.c
===================================================================
--- synctex.orig/synctex_parser_utils.c
+++ synctex/synctex_parser_utils.c
@@ -128,7 +128,7 @@ int _synctex_log(int level, const char *
@@ -129,7 +129,7 @@ int _synctex_log(int level, const char *
OutputDebugStringA("\n");
free(buff);
}

View file

@ -91,6 +91,7 @@ int _synctex_log(int level, const char * prompt, const char * reason, ...) SYNCT
int _synctex_log(int level, const char * prompt, const char * reason, ...) {
va_list arg;
int result;
va_start(arg, reason);
# ifdef SYNCTEX_RECENT_WINDOWS
{/* This code is contributed by William Blum.
As it does not work on some older computers,
@ -150,6 +151,7 @@ int _synctex_log(int level, const char * prompt, const char * reason, ...) {
result += vfprintf(where, reason, arg);
result += fprintf(where,"\n");
# endif
va_end(arg);
return result;
}