File fontforge-CVE-2017-17521.patch of Package fontforge.38208
From 29c26c16477b1b716a96fec6d0c2f985e1ab4d5a Mon Sep 17 00:00:00 2001
From: Jeremy Tan <jtanx@outlook.com>
Date: Sat, 9 Oct 2021 10:25:09 +0800
Subject: [PATCH] Move help to gutils
---
CMakeLists.txt | 2 +-
fontforgeexe/uiutil.c | 100 -----------------------------------------
gdraw/gresedit.c | 5 +--
gutils/gutils.c | 102 ++++++++++++++++++++++++++++++++++++++++++
inc/gutils.h | 1 +
5 files changed, 106 insertions(+), 104 deletions(-)
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,7 +99,7 @@
find_package(Freetype 2.3.7 REQUIRED)
find_package(Gettext REQUIRED)
find_package_with_target(Intl REQUIRED)
-find_package(GLIB 2.6 REQUIRED COMPONENTS gio)
+find_package(GLIB 2.6 REQUIRED COMPONENTS gio gobject)
find_package(Iconv REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(MathLib REQUIRED)
--- a/fontforgeexe/uiutil.c
+++ b/fontforgeexe/uiutil.c
@@ -40,106 +40,6 @@
#define ACTIVE_BORDER (_ggadget_Default_Box.active_border)
#define MAIN_FOREGROUND (_ggadget_Default_Box.main_foreground)
-
-static char* SupportedLocale(const char *locale, const char *fullspec, const char *filename) {
-/* If there's additional help files written for other languages, then check */
-/* to see if this local matches the additional help message language. If so */
-/* then report back that there's another language available to use for help */
-/* NOTE: If Docs are not maintained very well, maybe comment-out lang here. */
- int i;
- /* list languages in specific to generic order, ie: en_CA, en_GB, en... */
- static char *supported[] = { "de","ja", NULL }; /* other html lang list */
-
- for ( i=0; supported[i]!=NULL; ++i ) {
- if ( strcmp(locale,supported[i])==0 ) {
- char *pt = strrchr(filename, '/');
- return smprintf("%s/old/%s/%s", fullspec, supported[i], pt ? pt : filename);
- }
- }
- return NULL;
-}
-
-static char* CheckSupportedLocale(const char *fullspec, const char *filename) {
-/* Add Browser HELP for this local if there's more html docs for this local */
-
- /* KANOU has provided a japanese translation of the docs */
- /* Edward Lee is working on traditional chinese docs */
- const char *loc = getenv("LC_ALL");
- char buffer[40], *pt;
-
- if ( loc==NULL ) loc = getenv("LC_CTYPE");
- if ( loc==NULL ) loc = getenv("LANG");
- if ( loc==NULL ) loc = getenv("LC_MESSAGES");
- if ( loc==NULL )
- return NULL;
-
- /* first, try checking entire string */
- strncpy(buffer,loc,sizeof(buffer));
- buffer[sizeof(buffer)-1] = '\0';
- pt = SupportedLocale(buffer, fullspec, filename);
- if (pt) {
- return pt;
- }
-
- /* parse possible suffixes, such as .UTF-8, then try again */
- if ( (pt=strchr(buffer,'.'))!=NULL ) {
- *pt = '\0';
- pt = SupportedLocale(buffer, fullspec, filename);
- if (pt) {
- return pt;
- }
- }
-
- /* parse possible suffixes such as _CA, _GB, and try again */
- if ( (pt=strchr(buffer,'_'))!=NULL ) {
- *pt = '\0';
- return SupportedLocale(buffer, fullspec, filename);
- }
-
- return NULL;
-}
-
-void help(const char *file, const char *section) {
- if (!file) {
- return;
- } else if (strstr(file, "://")) {
- g_app_info_launch_default_for_uri(file, NULL, NULL);
- return;
- } else if (!section) {
- section = "";
- }
-
- bool launched = false;
- const char *help = getHelpDir();
- if (help) {
- char *path = CheckSupportedLocale(help, file);
- if (!path) {
- path = smprintf("%s/%s", help, file);
- if (!path) {
- return;
- }
- }
-
- GFile *gfile = g_file_new_for_path(path);
- free(path);
-
- if (g_file_query_exists(gfile, NULL)) {
- gchar* uri = g_file_get_uri(gfile);
- path = smprintf("%s%s", uri, section);
- launched = g_app_info_launch_default_for_uri(path, NULL, NULL);
- g_free(uri);
- free(path);
- }
- g_object_unref(gfile);
- }
-
- if (!launched) {
- char *path = smprintf("https://fontforge.org/docs/%s%s", file, section);
- g_app_info_launch_default_for_uri(path, NULL, NULL);
- free(path);
- }
-}
-
static void UI_IError(const char *format,...) {
va_list ap;
char buffer[300];
--- a/gdraw/gresedit.c
+++ b/gdraw/gresedit.c
@@ -31,8 +31,10 @@
#include "ggadget.h"
#include "ggadgetP.h"
#include "gresedit.h"
+#include "gutils.h"
#include "gwidget.h"
#include "ustring.h"
+#include "gkeysym.h"
struct tofree {
GGadgetCreateData *gcd;
@@ -953,13 +955,17 @@
static int gre_e_h(GWindow gw, GEvent *event) {
if ( event->type==et_close ) {
- GRE *gre = GDrawGetUserData(gw);
- GRE_DoCancel(gre);
+ GRE *gre = GDrawGetUserData(gw);
+ GRE_DoCancel(gre);
} else if ( event->type == et_char ) {
-return( false );
+ if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
+ help("ui/misc/resedit.html", NULL);
+ return true;
+ }
+ return false;
}
return( true );
-}
+}
static void GResEditDlg(GResInfo *all,const char *def_res_file,void (*change_res_filename)(const char *)) {
GResInfo *res, *parent;
--- a/gutils/gutils.c
+++ b/gutils/gutils.c
@@ -28,7 +28,10 @@
#include <fontforge-config.h>
#include "basics.h"
+#include "gfile.h"
#include "gutils.h"
+#include "ustring.h"
+#include "utype.h"
#include "ffglib.h"
@@ -70,3 +73,102 @@
return st_time;
}
+
+static char* SupportedLocale(const char *locale, const char *fullspec, const char *filename) {
+/* If there's additional help files written for other languages, then check */
+/* to see if this local matches the additional help message language. If so */
+/* then report back that there's another language available to use for help */
+/* NOTE: If Docs are not maintained very well, maybe comment-out lang here. */
+ int i;
+ /* list languages in specific to generic order, ie: en_CA, en_GB, en... */
+ static char *supported[] = { "de","ja", NULL }; /* other html lang list */
+
+ for ( i=0; supported[i]!=NULL; ++i ) {
+ if ( strcmp(locale,supported[i])==0 ) {
+ char *pt = strrchr(filename, '/');
+ return smprintf("%s/old/%s/%s", fullspec, supported[i], pt ? pt : filename);
+ }
+ }
+ return NULL;
+}
+
+static char* CheckSupportedLocale(const char *fullspec, const char *filename) {
+/* Add Browser HELP for this local if there's more html docs for this local */
+
+ /* KANOU has provided a japanese translation of the docs */
+ /* Edward Lee is working on traditional chinese docs */
+ const char *loc = getenv("LC_ALL");
+ char buffer[40], *pt;
+
+ if ( loc==NULL ) loc = getenv("LC_CTYPE");
+ if ( loc==NULL ) loc = getenv("LANG");
+ if ( loc==NULL ) loc = getenv("LC_MESSAGES");
+ if ( loc==NULL )
+ return NULL;
+
+ /* first, try checking entire string */
+ strncpy(buffer,loc,sizeof(buffer));
+ buffer[sizeof(buffer)-1] = '\0';
+ pt = SupportedLocale(buffer, fullspec, filename);
+ if (pt) {
+ return pt;
+ }
+
+ /* parse possible suffixes, such as .UTF-8, then try again */
+ if ( (pt=strchr(buffer,'.'))!=NULL ) {
+ *pt = '\0';
+ pt = SupportedLocale(buffer, fullspec, filename);
+ if (pt) {
+ return pt;
+ }
+ }
+
+ /* parse possible suffixes such as _CA, _GB, and try again */
+ if ( (pt=strchr(buffer,'_'))!=NULL ) {
+ *pt = '\0';
+ return SupportedLocale(buffer, fullspec, filename);
+ }
+
+ return NULL;
+}
+
+void help(const char *file, const char *section) {
+ if (!file) {
+ return;
+ } else if (strstr(file, "://")) {
+ g_app_info_launch_default_for_uri(file, NULL, NULL);
+ return;
+ } else if (!section) {
+ section = "";
+ }
+
+ bool launched = false;
+ const char *help = getHelpDir();
+ if (help) {
+ char *path = CheckSupportedLocale(help, file);
+ if (!path) {
+ path = smprintf("%s/%s", help, file);
+ if (!path) {
+ return;
+ }
+ }
+
+ GFile *gfile = g_file_new_for_path(path);
+ free(path);
+
+ if (g_file_query_exists(gfile, NULL)) {
+ gchar* uri = g_file_get_uri(gfile);
+ path = smprintf("%s%s", uri, section);
+ launched = g_app_info_launch_default_for_uri(path, NULL, NULL);
+ g_free(uri);
+ free(path);
+ }
+ g_object_unref(gfile);
+ }
+
+ if (!launched) {
+ char *path = smprintf("https://fontforge.org/docs/%s%s", file, section);
+ g_app_info_launch_default_for_uri(path, NULL, NULL);
+ free(path);
+ }
+}
--- a/inc/gutils.h
+++ b/inc/gutils.h
@@ -36,5 +36,6 @@
extern const char *GetAuthor(void);
extern time_t GetTime(void);
extern time_t GetST_MTime(struct stat s);
+extern void help(const char *filename, const char *section);
#endif /* FONTFORGE_GUTILS_H */