hjn_hyphen_load_file patch for sandboxing by Pawel Hajdan

This commit is contained in:
László Németh 2013-03-18 10:49:03 +00:00
parent 327252245c
commit 3bea3aed15
5 changed files with 24 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2013-03-18 László Németh <nemeth at numbertext dot org>:
* Makefile.am, Makefile.in: set -version-info
2013-03-12 Paweł Hajdan <phajdan at google>:
* hyphen.h, hyphen.c: add hnj_hyphen_load_file() for sandboxing
2012-09-13 László Németh <nemeth at numbertext dot org>: 2012-09-13 László Németh <nemeth at numbertext dot org>:
* hyphen.c: fdo#43931: removing hard hyphen hyphenation for LibreOffice * hyphen.c: fdo#43931: removing hard hyphen hyphenation for LibreOffice

View File

@ -2,7 +2,7 @@ SUBDIRS= doc tests
lib_LTLIBRARIES = libhyphen.la lib_LTLIBRARIES = libhyphen.la
libhyphen_la_SOURCES = hnjalloc.c hyphen.c libhyphen_la_SOURCES = hnjalloc.c hyphen.c
libhyphen_la_LDFLAGS = -version-info 2:1:2 libhyphen_la_LDFLAGS = -version-info 3:0:3
include_HEADERS = hyphen.h include_HEADERS = hyphen.h
noinst_HEADERS = hnjalloc.h noinst_HEADERS = hnjalloc.h

View File

@ -288,7 +288,7 @@ top_srcdir = @top_srcdir@
SUBDIRS = doc tests SUBDIRS = doc tests
lib_LTLIBRARIES = libhyphen.la lib_LTLIBRARIES = libhyphen.la
libhyphen_la_SOURCES = hnjalloc.c hyphen.c libhyphen_la_SOURCES = hnjalloc.c hyphen.c
libhyphen_la_LDFLAGS = -version-info 2:1:2 libhyphen_la_LDFLAGS = -version-info 3:0:3
include_HEADERS = hyphen.h include_HEADERS = hyphen.h
noinst_HEADERS = hnjalloc.h noinst_HEADERS = hnjalloc.h
substrings_SOURCES = substrings.c substrings_SOURCES = substrings.c

View File

@ -373,20 +373,29 @@ void hnj_hyphen_load_line(char * buf, HyphenDict * dict, HashTab * hashtab) {
HyphenDict * HyphenDict *
hnj_hyphen_load (const char *fn) hnj_hyphen_load (const char *fn)
{
HyphenDict *result;
FILE *f;
f = fopen (fn, "r");
if (f == NULL)
return NULL;
result = hnj_hyphen_load_file(f);
fclose(f);
return result;
}
HyphenDict *
hnj_hyphen_load_file (FILE *f)
{ {
HyphenDict *dict[2]; HyphenDict *dict[2];
HashTab *hashtab; HashTab *hashtab;
FILE *f;
char buf[MAX_CHARS]; char buf[MAX_CHARS];
int nextlevel = 0; int nextlevel = 0;
int i, j, k; int i, j, k;
HashEntry *e; HashEntry *e;
int state_num = 0; int state_num = 0;
f = fopen (fn, "r");
if (f == NULL)
return NULL;
// loading one or two dictionaries (separated by NEXTLEVEL keyword) // loading one or two dictionaries (separated by NEXTLEVEL keyword)
for (k = 0; k < 2; k++) { for (k = 0; k < 2; k++) {
hashtab = hnj_hash_new (); hashtab = hnj_hash_new ();
@ -497,7 +506,6 @@ for (k = 0; k < 2; k++) {
#endif #endif
state_num = 0; state_num = 0;
} }
fclose(f);
if (nextlevel) dict[0]->nextlevel = dict[1]; if (nextlevel) dict[0]->nextlevel = dict[1];
else { else {
dict[1] -> nextlevel = dict[0]; dict[1] -> nextlevel = dict[0];

View File

@ -94,6 +94,7 @@ struct _HyphenTrans {
}; };
HyphenDict *hnj_hyphen_load (const char *fn); HyphenDict *hnj_hyphen_load (const char *fn);
HyphenDict *hnj_hyphen_load_file (FILE *f);
void hnj_hyphen_free (HyphenDict *dict); void hnj_hyphen_free (HyphenDict *dict);
/* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */ /* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */