Package: libpoppler4 Version: 0.10.6-1 Severity: normal
poppler uses the strtok() function, while it's not safe to do so in a multi-threaded application (or in a library aimed to be used in a multi-threaded applications).
The attached patch fixes the problem. -- Jakub Wilk
diff --git a/fofi/FoFiType1.cc b/fofi/FoFiType1.cc --- a/fofi/FoFiType1.cc +++ b/fofi/FoFiType1.cc @@ -192,6 +192,7 @@ char buf[256]; char c; int n, code, i, j; + char *tokptr; for (i = 1, line = (char *)file; i <= 100 && line && (!name || !encoding); @@ -202,7 +203,7 @@ strncpy(buf, line, 255); buf[255] = '\0'; if ((p = strchr(buf+9, '/')) && - (p = strtok(p+1, " \t\n\r"))) { + (p = strtok_r(p+1, " \t\n\r", &tokptr))) { name = copyString(p); } line = getNextLine(line); @@ -270,8 +271,8 @@ } } } else { - if (strtok(buf, " \t") && - (p = strtok(NULL, " \t\n\r")) && !strcmp(p, "def")) { + if (strtok_r(buf, " \t", &tokptr) && + (p = strtok_r(NULL, " \t\n\r", &tokptr)) && !strcmp(p, "def")) { break; } } diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc --- a/poppler/CharCodeToUnicode.cc +++ b/poppler/CharCodeToUnicode.cc @@ -124,6 +124,7 @@ Unicode *uBuf = (Unicode *)gmallocn(uBufSize, sizeof(Unicode)); CharCodeToUnicode *ctu; int line, n, i; + char *tokptr; if (!(f = fopen(fileName->getCString(), "r"))) { gfree(uBuf); @@ -142,14 +143,14 @@ line = 0; while (getLine(buf, sizeof(buf), f)) { ++line; - if (!(tok = strtok(buf, " \t\r\n")) || + if (!(tok = strtok_r(buf, " \t\r\n", &tokptr)) || sscanf(tok, "%x", &u0) != 1) { error(-1, "Bad line (%d) in unicodeToUnicode file '%s'", line, fileName->getCString()); continue; } n = 0; - while ((tok = strtok(NULL, " \t\r\n"))) { + while ((tok = strtok_r(NULL, " \t\r\n", &tokptr))) { if (n >= uBufSize) { uBufSize += 8; diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -712,6 +712,7 @@ char buf[256]; int line; Unicode u; + char *tokptr; if (!(f = fopen(name->getCString(), "r"))) { error(-1, "Couldn't open 'nameToUnicode' file '%s'", @@ -720,8 +721,8 @@ } line = 1; while (getLine(buf, sizeof(buf), f)) { - tok1 = strtok(buf, " \t\r\n"); - tok2 = strtok(NULL, " \t\r\n"); + tok1 = strtok_r(buf, " \t\r\n", &tokptr); + tok2 = strtok_r(NULL, " \t\r\n", &tokptr); if (tok1 && tok2) { sscanf(tok1, "%x", &u); nameToUnicode->add(tok2, u); diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -310,6 +310,7 @@ void PDFDoc::checkHeader() { char hdrBuf[headerSearchSize+1]; char *p; + char *tokptr; int i; pdfVersion = 0; @@ -327,7 +328,7 @@ return; } str->moveStart(i); - if (!(p = strtok(&hdrBuf[i+5], " \t\n\r"))) { + if (!(p = strtok_r(&hdrBuf[i+5], " \t\n\r", &tokptr))) { error(-1, "May not be a PDF file (continuing anyway)"); return; } diff --git a/poppler/UnicodeMap.cc b/poppler/UnicodeMap.cc --- a/poppler/UnicodeMap.cc +++ b/poppler/UnicodeMap.cc @@ -43,6 +43,7 @@ char buf[256]; int line, nBytes, i, x; char *tok1, *tok2, *tok3; + char *tokptr; if (!(f = globalParams->getUnicodeMapFile(encodingNameA))) { error(-1, "Couldn't find unicodeMap file for the '%s' encoding", @@ -58,9 +59,9 @@ line = 1; while (getLine(buf, sizeof(buf), f)) { - if ((tok1 = strtok(buf, " \t\r\n")) && - (tok2 = strtok(NULL, " \t\r\n"))) { - if (!(tok3 = strtok(NULL, " \t\r\n"))) { + if ((tok1 = strtok_r(buf, " \t\r\n", &tokptr)) && + (tok2 = strtok_r(NULL, " \t\r\n", &tokptr))) { + if (!(tok3 = strtok_r(NULL, " \t\r\n", &tokptr))) { tok3 = tok2; tok2 = tok1; }