mitchell852 closed pull request #2847: Fix TM nil panic in CRConfig validation
URL: https://github.com/apache/trafficcontrol/pull/2847
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_monitor/towrap/towrap.go b/traffic_monitor/towrap/towrap.go
index 55e80e3e0..36e148c08 100644
--- a/traffic_monitor/towrap/towrap.go
+++ b/traffic_monitor/towrap/towrap.go
@@ -196,8 +196,16 @@ func (s TrafficOpsSessionThreadsafe) CRConfigHistory() 
[]CRConfigStat {
 }
 
 func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc *tc.CRConfig, cdn 
string) error {
+       if crc.Stats.CDNName == nil {
+               return errors.New("CRConfig.Stats.CDN missing")
+       }
+       if crc.Stats.DateUnixSeconds == nil {
+               return errors.New("CRConfig.Stats.Date missing")
+       }
+
        // Note this intentionally takes intended CDN, rather than trusting 
crc.Stats
        lastCrc, lastCrcTime, lastCrcStats := s.lastCRConfig.Get(cdn)
+
        if lastCrc == nil {
                return nil
        }
@@ -205,12 +213,13 @@ func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc 
*tc.CRConfig, cdn string
                log.Warnln("TrafficOpsSessionThreadsafe.CRConfigValid returning 
no error, but last CRConfig Date was missing!")
                return nil
        }
+       if lastCrcStats.CDNName == nil {
+               log.Warnln("TrafficOpsSessionThreadsafe.CRConfigValid returning 
no error, but last CRConfig CDN was missing!")
+               return nil
+       }
        if *lastCrcStats.CDNName != *crc.Stats.CDNName {
                return errors.New("CRConfig.Stats.CDN " + *crc.Stats.CDNName + 
" different than last received CRConfig.Stats.CDNName " + *lastCrcStats.CDNName 
+ " received at " + lastCrcTime.Format(time.RFC3339Nano))
        }
-       if crc.Stats.DateUnixSeconds == nil {
-               return errors.New("CRConfig.Stats.Date missing")
-       }
        if *lastCrcStats.DateUnixSeconds > *crc.Stats.DateUnixSeconds {
                return errors.New("CRConfig.Stats.Date " + 
strconv.FormatInt(*crc.Stats.DateUnixSeconds, 10) + " older than last received 
CRConfig.Stats.Date " + strconv.FormatInt(*lastCrcStats.DateUnixSeconds, 10) + 
" received at " + lastCrcTime.Format(time.RFC3339Nano))
        }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to