github-vet / github-vet/rangeloop-pointer-findings
gitter-badger/cecil: core/job-alerter.go; 120 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [gitter-badger/cecil](https://www.github.com/gitter-badger/cecil) at [core/job-alerter.go](https://github.com/gitter-badger/cecil/blob/13e9c00c34840907b6e4b6b3277fc69ac651c614/core/job-alerter.go#L50-L169)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
>
[Click here to see the code in its original context.](https://github.com/gitter-badger/cecil/blob/13e9c00c34840907b6e4b6b3277fc69ac651c614/core/job-alerter.go#L50-L169)
Click here to show the 120 line(s) of Go which triggered the analyzer.
```go
for _, expiringLease := range expiringLeases {
switch expiringLease.NumTimesAllertedAboutExpiry {
case 0:
{
}
case 1:
{
if !expiringLease.ExpiresAt.Before(time.Now().UTC().Add(s.Config().Lease.SecondWarningBeforeExpiry)) {
continue ExpiringLeasesIterator
}
}
default:
{
continue ExpiringLeasesIterator
}
}
Logger.Info("Expiring lease",
"lease_id", expiringLease.ID,
"group_type", expiringLease.GroupType.String(),
"group_uid", expiringLease.GroupUID,
)
owner, err := s.GetOwnerByID(expiringLease.OwnerID)
if err != nil {
Logger.Error("error while fetching owner of expiring lease", "err", err)
if err == gorm.ErrRecordNotFound {
return err
}
return err
}
// these will be used to compose the urls and verify the requests
tokenOnce := uuid.NewV4().String() // one-time token
expiringLease.TokenOnce = tokenOnce
expiringLease.NumTimesAllertedAboutExpiry++
s.DB.Save(&expiringLease)
// URL to extend lease
extendURL, err := s.EmailActionGenerateSignedURL("extend", expiringLease.UUID, HashString(expiringLease.GroupUID), tokenOnce)
if err != nil {
// TODO: notify admins
return fmt.Errorf("error while generating signed URL: %v", err)
}
// URL to terminate lease
terminateURL, err := s.EmailActionGenerateSignedURL("terminate", expiringLease.UUID, HashString(expiringLease.GroupUID), tokenOnce)
if err != nil {
// TODO: notify admins
return fmt.Errorf("error while generating signed URL: %v", err)
}
var AWSResourceID string
AWSResourceID = expiringLease.GroupUID
var emailValues = map[string]interface{}{
"owner_email": owner.Email,
"created_at": expiringLease.CreatedAt.Format("2006-01-02 15:04:05 GMT"),
"extend_by": s.Config().Lease.Duration.String(),
"expires_at": expiringLease.ExpiresAt.Format("2006-01-02 15:04:05 GMT"),
"lease_duration": expiringLease.ExpiresAt.Sub(expiringLease.CreatedAt).String(),
"lease_terminate_url": terminateURL,
"lease_extend_url": extendURL,
"resource_region": expiringLease.Region,
}
emailValues["lease_id"] = expiringLease.ID
emailValues["group_type"] = expiringLease.GroupType.String()
emailValues["group_uid"] = expiringLease.GroupUID
if expiringLease.AwsContainerName != "" {
emailValues["aws_container_name"] = expiringLease.AwsContainerName
}
{
instances, err := s.ActiveInstancesForGroup(expiringLease.AccountID, &expiringLease.CloudaccountID, expiringLease.GroupUID)
if err != nil {
return err
}
emailValues["instances"] = instances
}
newEmailBody, err := tools.CompileEmailTemplate(
"lease-expiring.html",
emailValues,
)
if err != nil {
return err
}
newEmailSubject := fmt.Sprintf("%v Lease %v will expire soon", expiringLease.GroupType.EmailDisplayString(), expiringLease.ID)
switch expiringLease.NumTimesAllertedAboutExpiry {
case 1:
newEmailSubject = fmt.Sprintf("%v %v", newEmailSubject, "(1st warning)")
case 2:
newEmailSubject = fmt.Sprintf("%v %v", newEmailSubject, "(final warning)")
}
s.Queues().NotifierQueue().PushTask(tasks.NotifierTask{
AccountID: expiringLease.AccountID, // this will also trigger send to Slack
To: owner.Email,
Subject: newEmailSubject,
BodyHTML: newEmailBody,
BodyText: newEmailBody,
NotificationMeta: notification.NotificationMeta{
NotificationType: notification.InstanceWillExpire,
LeaseUUID: expiringLease.UUID,
AWSResourceID: AWSResourceID,
//ResourceType: expiringLease.ResourceType,
},
})
}
```
Click here to show extra information the analyzer produced.
```
No path was found through the callgraph that could lead to a function which writes a pointer argument.
No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.
root signature {Save 1} was not found in the callgraph; reference was passed directly to third-party code
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 13e9c00c34840907b6e4b6b3277fc69ac651c614
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.