mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Geo: validate long,lat passed by user via API
This commit is contained in:
parent
5254c2d3c3
commit
5e04189887
20
deps/geohash-int/geohash.c
vendored
20
deps/geohash-int/geohash.c
vendored
@ -112,19 +112,23 @@ static inline uint64_t deinterleave64(uint64_t interleaved) {
|
||||
void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
|
||||
/* These are constraints from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
|
||||
/* We can't geocode at the north/south pole. */
|
||||
long_range->max = 180.0;
|
||||
long_range->min = -180.0;
|
||||
lat_range->max = 85.05112878;
|
||||
lat_range->min = -85.05112878;
|
||||
long_range->max = GEO_LONG_MAX;
|
||||
long_range->min = GEO_LONG_MIN;
|
||||
lat_range->max = GEO_LAT_MAX;
|
||||
lat_range->min = GEO_LAT_MIN;
|
||||
}
|
||||
|
||||
int geohashEncode(GeoHashRange *long_range, GeoHashRange *lat_range,
|
||||
double longitude, double latitude, uint8_t step,
|
||||
GeoHashBits *hash) {
|
||||
if (NULL == hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) ||
|
||||
RANGEPISZERO(long_range)) {
|
||||
return 0;
|
||||
}
|
||||
/* Check basic arguments sanity. */
|
||||
if (hash == NULL || step > 32 || step == 0 ||
|
||||
RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0;
|
||||
|
||||
/* Return an error when trying to index outside the supported
|
||||
* constraints. */
|
||||
if (longitude > 180 || longitude < -180 ||
|
||||
latitude > 85.05112878 || latitude < -85.05112878) return 0;
|
||||
|
||||
hash->bits = 0;
|
||||
hash->step = step;
|
||||
|
8
deps/geohash-int/geohash.h
vendored
8
deps/geohash-int/geohash.h
vendored
@ -44,7 +44,13 @@ extern "C" {
|
||||
#define RANGEISZERO(r) (!(r).max && !(r).min)
|
||||
#define RANGEPISZERO(r) (r == NULL || RANGEISZERO(*r))
|
||||
|
||||
#define GEO_STEP_MAX 26
|
||||
#define GEO_STEP_MAX 26 /* 26*2 = 52 bits. */
|
||||
|
||||
/* Limits from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
|
||||
#define GEO_LAT_MIN -85.05112878
|
||||
#define GEO_LAT_MAX 85.05112878
|
||||
#define GEO_LONG_MIN -180
|
||||
#define GEO_LONG_MAX 180
|
||||
|
||||
typedef enum {
|
||||
GEOHASH_NORTH = 0,
|
||||
|
@ -98,6 +98,12 @@ int extractLongLatOrReply(redisClient *c, robj **argv,
|
||||
REDIS_OK) {
|
||||
return REDIS_ERR;
|
||||
}
|
||||
if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX ||
|
||||
xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) {
|
||||
addReplySds(c, sdscatprintf(sdsempty(),
|
||||
"-ERR invalid longitude,latitude pair %f,%f\r\n",xy[0],xy[1]));
|
||||
return REDIS_ERR;
|
||||
}
|
||||
}
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user