Skip to content

Commit 93cf334

Browse files
committed
[Redis] Improve Error Handling On Port Parsing
* Use correct error-handling as specified in the strtoul manpages.
1 parent e2e5b9f commit 93cf334

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

include/mapcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ typedef struct mapcache_cache_redis mapcache_cache_redis;
610610
struct mapcache_cache_redis {
611611
mapcache_cache cache;
612612
char *host;
613-
unsigned int port;
613+
unsigned long int port;
614614
};
615615

616616
/**

lib/cache_redis.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "mapcache.h"
3434
#include <apr_strings.h>
35+
#include <limits.h>
36+
#include <errno.h>
3537

3638
#define REDIS_GET_CACHE(t) ((mapcache_cache_redis*)t->tileset->cache)
3739
#define REDIS_GET_TILE_KEY(c, t) (mapcache_util_get_tile_key(c, t, NULL, " \r\n\t\f\e\a\b", "#"))
@@ -204,9 +206,11 @@ static void _mapcache_cache_redis_configuration_parse_xml(mapcache_context *ctx,
204206
ctx->set_error(ctx, 400, "cache %s: redis cache with no <port>", cache->name);
205207
return;
206208
} else {
207-
char *endptr;
208-
int iport = (int)strtol(xport->txt, &endptr, 10);
209-
if(*endptr != 0) {
209+
unsigned long int iport = strtoul(xport->txt, NULL, 10);
210+
if(iport == ULONG_MAX && errno == ERANGE) {
211+
ctx->set_error(ctx, 400, "port value %s too large to be parsed for redis cache %s", xport->txt, cache->name);
212+
return;
213+
} else if(iport == 0) {
210214
ctx->set_error(ctx, 400, "failed to parse port value %s for redis cache %s", xport->txt, cache->name);
211215
return;
212216
}

0 commit comments

Comments
 (0)