Skip to content

Commit

Permalink
fix message traversal error
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeiferj committed Nov 3, 2023
1 parent 847a8fb commit 6cd6b79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
18 changes: 3 additions & 15 deletions generate_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,15 @@ func PointInBox(ax float64, ay float64, bxMin float64, byMin float64, bxMax floa

var AREAS = GenerateAreas()

func FindWaysAroundLocation(lat float64, lon float64) (Offline, error) {
offline := Offline{}
func FindWaysAroundLocation(lat float64, lon float64) ([]byte, error) {
for _, area := range AREAS {
inBox := PointInBox(lat, lon, area.MinLat, area.MinLon, area.MaxLat, area.MaxLon)
if inBox {
boundsName := GenerateBoundsFileName(area.MinLat, area.MinLon, area.MaxLat, area.MaxLon)
fmt.Println(boundsName)
data, err := os.ReadFile(boundsName)
if err != nil {
return offline, err
}
msg, err := capnp.UnmarshalPacked(data)
if err != nil {
return offline, err
}
offline, err := ReadRootOffline(msg)
if err != nil {
return offline, err
}
return offline, nil
return data, err
}
}
return offline, nil
return []uint8{}, nil
}
19 changes: 13 additions & 6 deletions mapd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
"capnproto.org/go/capnp/v3"
"encoding/json"
"flag"
"fmt"
"time"
)

type State struct {
Data []uint8
Result Offline
Way CurrentWay
NextWay Way
Expand Down Expand Up @@ -64,11 +66,19 @@ func main() {
coordinates, _ := GetParam(LAST_GPS_POSITION_PERSIST)
err := json.Unmarshal(coordinates, &pos)
loge(err)
state.Result, err = FindWaysAroundLocation(pos.Latitude, pos.Longitude)
state.Data, err = FindWaysAroundLocation(pos.Latitude, pos.Longitude)
loge(err)

for {
DownloadIfTriggered()

msg, err := capnp.UnmarshalPacked(state.Data)
loge(err)
if err == nil {
offline, err := ReadRootOffline(msg)
loge(err)
state.Result = offline
}
coordinates, err := GetParam(LAST_GPS_POSITION)
if err != nil {
loge(err)
Expand All @@ -79,7 +89,6 @@ func main() {
loge(err)
continue
}

state.Position = pos

if !PointInBox(pos.Latitude, pos.Longitude, state.Result.MinLat(), state.Result.MinLon(), state.Result.MaxLat(), state.Result.MaxLon()) {
Expand All @@ -88,11 +97,8 @@ func main() {
state.Way = CurrentWay{}
state.Result = Offline{}
state.NextWay = Way{}
res, err := FindWaysAroundLocation(pos.Latitude, pos.Longitude)
state.Data, err = FindWaysAroundLocation(pos.Latitude, pos.Longitude)
loge(err)
if err == nil {
state.Result = res
}
}
way, err := GetCurrentWay(&state, pos.Latitude, pos.Longitude)
if err == nil {
Expand Down Expand Up @@ -121,6 +127,7 @@ func main() {
Longitude: state.MatchNode.Longitude(),
Speedlimit: nextSpeedLimit,
})

loge(err)
if err == nil {
err := PutParam(NEXT_MAP_SPEED_LIMIT, data)
Expand Down

0 comments on commit 6cd6b79

Please sign in to comment.