Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
5e041898
Commit
5e041898
authored
Jul 06, 2015
by
antirez
Browse files
Geo: validate long,lat passed by user via API
parent
5254c2d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
deps/geohash-int/geohash.c
View file @
5e041898
...
...
@@ -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
.
05112
878
;
lat_range
->
min
=
-
85
.
05112
878
;
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
.
05112
878
||
latitude
<
-
85
.
05112
878
)
return
0
;
hash
->
bits
=
0
;
hash
->
step
=
step
;
...
...
deps/geohash-int/geohash.h
View file @
5e041898
...
...
@@ -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
,
...
...
src/geo.c
View file @
5e041898
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment