diff --git a/database/queue.go b/database/queue.go index 2a6d194..55ca3d7 100644 --- a/database/queue.go +++ b/database/queue.go @@ -84,7 +84,12 @@ func QueuedQuery(query string, args ...interface{}) (*sql.Rows, error) { var rows *sql.Rows err := GetQueue().EnqueueOperation(func() error { var err error - rows, err = db.Query(query, args...) + stmt, err := db.Prepare(query) + if err != nil { + return err + } + + rows, err = stmt.Query(args...) return err }) return rows, err diff --git a/main.go b/main.go index 31dd4c8..0014aa5 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "math" "net/http" "strings" "time" @@ -656,7 +657,13 @@ func main() { return } - res, err := http.Get(fmt.Sprintf("https://api.mapbox.com/directions/v5/mapbox/walking/%f,%f;%f,%f?alternatives=true&geometries=geojson&language=en&overview=full&steps=true&access_token=%s", obj.StartX, obj.StartY, obj.EndX, obj.EndY, util.Config.Mapbox.AccessToken)) + var validateCoordinate func(float64) float64 = func(x float64) float64 { + return math.Max(-90, math.Min(90, x)) + } + + var sX, sY, eX, eY float64 = validateCoordinate(obj.StartX), validateCoordinate(obj.StartY), validateCoordinate(obj.EndX), validateCoordinate(obj.EndY) + + res, err := http.Get(fmt.Sprintf("https://api.mapbox.com/directions/v5/mapbox/walking/%f,%f;%f,%f?alternatives=true&geometries=geojson&language=en&overview=full&steps=true&access_token=%s", sX, sY, eX, eY, util.Config.Mapbox.AccessToken)) if err != nil { w.WriteHeader(http.StatusInternalServerError) diff --git a/util/config.go b/util/config.go index 9e894fe..faf4f1a 100644 --- a/util/config.go +++ b/util/config.go @@ -2,6 +2,7 @@ package util import ( "fmt" + "math" "os" "regexp" "strconv" @@ -100,7 +101,12 @@ func LoadEnvFile() { Log.Error("DATABASE_QUEUE_SIZE not an integer") os.Exit(1) } else { - Config.Database.QueueSize = int(i) + if i > math.MinInt32 && i < math.MaxInt32 { + Config.Database.QueueSize = int(i) + } else { + Log.Error("DATABASE_QUEUE_SIZE not within int32 range") + os.Exit(1) + } } } @@ -133,7 +139,12 @@ func LoadEnvFile() { Log.Error("SERVER_PORT not an integer") os.Exit(1) } else { - Config.Server.Port = int(i) + if i < math.MaxUint16 { + Config.Server.Port = int(i) + } else { + Log.Error("SERVER_PORT not within int16 range") + os.Exit(1) + } } }