Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fontcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ ft_cache *msGetFontCache() {
}

void msFontCacheSetup() {
#ifdef USE_THREAD
if (ft_caches)
msFontCacheCleanup();
#endif

#ifndef USE_THREAD
ft_cache *c = msGetFontCache();
Expand Down
7 changes: 6 additions & 1 deletion src/mapcairo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,12 @@ int msPreloadSVGSymbol(symbolObj *symbol) {
}
#else
{
cache->svgc = rsvg_handle_new_from_file(symbol->full_pixmap_path, NULL);
if (EQUALN(symbol->full_pixmap_path, "<?xml", 5))
cache->svgc = rsvg_handle_new_from_data(
(const guint8 *)symbol->full_pixmap_path,
strlen(symbol->full_pixmap_path), NULL);
else
cache->svgc = rsvg_handle_new_from_file(symbol->full_pixmap_path, NULL);
if (!cache->svgc) {
msSetError(MS_RENDERERERR, "failed to load svg file %s",
"msPreloadSVGSymbol()", symbol->full_pixmap_path);
Expand Down
17 changes: 17 additions & 0 deletions src/mapcompositingfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,15 @@ int msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb,
regmatch_t pmatch[3];

/* test for blurring filter */
#ifdef USE_PCRE2
{
char *pat = msPCRE2EscapeBracketBackslashes("blur\\(([0-9]+)\\)");
regcomp(&regex, pat, REG_EXTENDED);
free(pat);
}
#else
regcomp(&regex, "blur\\(([0-9]+)\\)", REG_EXTENDED);
#endif
rstatus = regexec(&regex, filter->filter, 2, pmatch, 0);
regfree(&regex);
if (!rstatus) {
Expand All @@ -195,7 +203,16 @@ int msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb,
}

/* test for translation filter */
#ifdef USE_PCRE2
{
char *pat = msPCRE2EscapeBracketBackslashes(
"translate\\((-?[0-9]+),(-?[0-9]+)\\)");
regcomp(&regex, pat, REG_EXTENDED);
free(pat);
}
#else
regcomp(&regex, "translate\\((-?[0-9]+),(-?[0-9]+)\\)", REG_EXTENDED);
#endif
rstatus = regexec(&regex, filter->filter, 3, pmatch, 0);
regfree(&regex);
if (!rstatus) {
Expand Down
5 changes: 3 additions & 2 deletions src/maplegend.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ int msEmbedLegend(mapObj *map, imageObj *img) {
!MS_MAP_RENDERER(map)->supports_pixel_buffer) {
imageType = msStrdup(map->imagetype); /* save format */
if MS_DRIVER_CAIRO(map->outputformat) {
#ifdef USE_SVG_CAIRO
#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
map->outputformat = msSelectOutputFormat( map, "svg" );
#else
map->outputformat = msSelectOutputFormat( map, "cairopng" );
Expand Down Expand Up @@ -1012,7 +1012,8 @@ int msEmbedLegend(mapObj *map, imageObj *img) {
}

legendSymbol->renderer = renderer;
legendSymbol->renderer_free_func = renderer->freeSymbol;
legendSymbol->renderer_free_func =
(void (*)(symbolObj *))renderer->freeSymbol;

legendSymbol->name = msStrdup(LEGEND_SYMBOL_NAME);

Expand Down
20 changes: 13 additions & 7 deletions src/mapmssql2008.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,13 @@ static void setConnError(msODBCconn *conn) {
conn->errorMessage[len] = 0;
}

#ifdef USE_ICONV
/* SPT-14135: every USE_ICONV branch below assumes a 2-byte wchar_t (true on
* Windows, false on Linux/glibc's 4-byte wchar_t), reinterpreting iconv's
* 2-byte-per-char UCS-2LE output as wchar_t elements and corrupting the
* connection string / SQL text / query results. Restrict the wide-char ODBC
* path (SQLDriverConnectW/SQLExecDirectW/SQL_WCHAR) to Windows; elsewhere
* fall back to the plain narrow-char path already used for non-ICONV builds. */
#if defined(USE_ICONV) && defined(_WIN32)
static SQLWCHAR *convertCwchartToSQLWCHAR(const wchar_t *inStr) {
SQLWCHAR *outStr;
int i, len;
Expand Down Expand Up @@ -785,7 +791,7 @@ static msODBCconn *mssql2008Connect(const char *connString) {
}

{
#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
wchar_t *decodedConnString =
msConvertWideStringFromUTF8(connString, "UCS-2LE");
SQLWCHAR outConnString[1024];
Expand Down Expand Up @@ -832,7 +838,7 @@ static int executeSQL(msODBCconn *conn, const char *sql) {

SQLCloseCursor(conn->hstmt);

#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
{
wchar_t *decodedSql = msConvertWideStringFromUTF8(sql, "UCS-2LE");
SQLWCHAR *decodedSqlSQLWCHAR = convertCwchartToSQLWCHAR(decodedSql);
Expand Down Expand Up @@ -1521,7 +1527,7 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string,

/* adding items to the select list */
for (t = 0; t < layer->numitems; t++) {
#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
query = msStringConcatenate(query, "convert(nvarchar(max), [");
#else
query = msStringConcatenate(query, "convert(varchar(max), [");
Expand Down Expand Up @@ -2307,7 +2313,7 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape,
return MS_FAILURE;
}

#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
SQLSMALLINT targetType = SQL_WCHAR;
#else
SQLSMALLINT targetType = SQL_CHAR;
Expand All @@ -2328,7 +2334,7 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape,
* include */
/* If we get SQL_NO_TOTAL we do not know how big buffer we need so
* we increase it with 512. */
#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
totalLen -= sizeof(wchar_t);
emptyLen = retLen != SQL_NO_TOTAL
? retLen - emptyLen + 2 * sizeof(wchar_t)
Expand All @@ -2354,7 +2360,7 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape,

if (totalLen > 0) {
/* Pop the value into the shape's value array */
#ifdef USE_ICONV
#if defined(USE_ICONV) && defined(_WIN32)
shape->values[t] =
msConvertWideStringToUTF8((wchar_t *)valueBuffer, "UCS-2LE");
msFree(valueBuffer);
Expand Down
83 changes: 83 additions & 0 deletions src/mapregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,83 @@
#include <regex.h>
#endif

#ifdef USE_PCRE2
/* PCRE2 escapes backslash inside [...]; POSIX regex doesn't. Double
* lone backslashes in brackets so PCRE2 sees a literal one too.
* Already-paired "\\" is left alone, so this is idempotent. */
MS_API_EXPORT(char *) msPCRE2EscapeBracketBackslashes(const char *expr) {
size_t len = strlen(expr);
char *out = (char *)msSmallMalloc(len * 2 + 1);
size_t oi = 0;
int in_bracket = 0;
size_t bracket_start = 0;

for (size_t i = 0; i < len;) {
char c = expr[i];

if (!in_bracket) {
if (c == '[') {
in_bracket = 1;
out[oi++] = c;
i++;
if (i < len && expr[i] == '^') {
out[oi++] = expr[i];
i++;
}
bracket_start = i;
continue;
}
out[oi++] = c;
i++;
continue;
}

if (c == ']' && i != bracket_start) {
in_bracket = 0;
out[oi++] = c;
i++;
continue;
}

/* [:class:], [.x.], [=x=] - pass through untouched */
if (c == '[' && i + 1 < len &&
(expr[i + 1] == ':' || expr[i + 1] == '.' || expr[i + 1] == '=')) {
char sub = expr[i + 1];
out[oi++] = expr[i];
out[oi++] = expr[i + 1];
i += 2;
while (i + 1 < len && !(expr[i] == sub && expr[i + 1] == ']')) {
out[oi++] = expr[i];
i++;
}
if (i + 1 < len) {
out[oi++] = expr[i];
out[oi++] = expr[i + 1];
i += 2;
}
continue;
}

if (c == '\\') {
out[oi++] = '\\';
out[oi++] = '\\';
if (i + 1 < len && expr[i + 1] == '\\') {
i += 2; /* already escaped */
} else {
i += 1; /* lone backslash - double it */
}
continue;
}

out[oi++] = c;
i++;
}

out[oi] = '\0';
return out;
}
#endif

MS_API_EXPORT(int) ms_regcomp(ms_regex_t *regex, const char *expr, int cflags) {
/* Must free in regfree() */
regex_t *sys_regex = (regex_t *)msSmallMalloc(sizeof(regex_t));
Expand All @@ -71,7 +148,13 @@ MS_API_EXPORT(int) ms_regcomp(ms_regex_t *regex, const char *expr, int cflags) {
reg_cflags |= REG_NOSUB;
if (cflags & MS_REG_NEWLINE)
reg_cflags |= REG_NEWLINE;
#ifdef USE_PCRE2
char *escaped_expr = msPCRE2EscapeBracketBackslashes(expr);
int ret = regcomp(sys_regex, escaped_expr, reg_cflags);
free(escaped_expr);
#else
int ret = regcomp(sys_regex, expr, reg_cflags);
#endif
if (ret != 0) {
free(regex->sys_regex);
regex->sys_regex = NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/mapregex.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ MS_API_EXPORT(int)
ms_regexec(const ms_regex_t *, const char *, size_t, ms_regmatch_t[], int);
MS_API_EXPORT(void) ms_regfree(ms_regex_t *);

#ifdef USE_PCRE2
MS_API_EXPORT(char *) msPCRE2EscapeBracketBackslashes(const char *);
#endif

#ifndef BUILDING_REGEX_PROXY

/* === regcomp.c === */
Expand Down
9 changes: 6 additions & 3 deletions src/maprendering.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ int msDrawLineSymbol(mapObj *map, imageObj *image, shapeObj *p, styleObj *style,
if (symbol->renderer_free_func)
symbol->renderer_free_func(symbol);

symbol->renderer_free_func = renderer->freeSymbol;
symbol->renderer_free_func =
(void (*)(symbolObj *))renderer->freeSymbol;
}

width = style->width * scalefactor;
Expand Down Expand Up @@ -775,7 +776,8 @@ int msDrawShadeSymbol(mapObj *map, imageObj *image, shapeObj *p,
if(symbol->renderer_free_func)
symbol->renderer_free_func(symbol);

symbol->renderer_free_func = renderer->freeSymbol;
symbol->renderer_free_func =
(void (*)(symbolObj *))renderer->freeSymbol;
}

if (style->offsetx != 0 || style->offsety != 0) {
Expand Down Expand Up @@ -927,7 +929,8 @@ int msDrawMarkerSymbol(mapObj *map, imageObj *image, pointObj *p,
if (symbol->renderer_free_func)
symbol->renderer_free_func(symbol);

symbol->renderer_free_func = renderer->freeSymbol;
symbol->renderer_free_func =
(void (*)(symbolObj *))renderer->freeSymbol;
}
if (preloadSymbol(&map->symbolset, symbol, renderer) != MS_SUCCESS) {
return MS_FAILURE;
Expand Down
Loading
Loading