Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 8549b64

Browse files
authored
fix-nodata-sql-injection (#954)
1 parent 34db457 commit 8549b64

File tree

1 file changed

+4
-5
lines changed
  • modules/nodata/config/service

1 file changed

+4
-5
lines changed

modules/nodata/config/service/host.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package service
1616

1717
import (
18-
"fmt"
1918
"log"
2019
"time"
2120
)
@@ -25,17 +24,17 @@ func GetHostsFromGroup(grpName string) map[string]int {
2524
hosts := make(map[string]int)
2625

2726
now := time.Now().Unix()
28-
q := fmt.Sprintf("SELECT host.id, host.hostname FROM grp_host AS gh "+
29-
" INNER JOIN host ON host.id=gh.host_id AND (host.maintain_begin > %d OR host.maintain_end < %d)"+
30-
" INNER JOIN grp ON grp.id=gh.grp_id AND grp.grp_name='%s'", now, now, grpName)
27+
sqlStatement := "SELECT host.id, host.hostname FROM grp_host AS gh " +
28+
" INNER JOIN host ON host.id=gh.host_id AND (host.maintain_begin > ? OR host.maintain_end < ?)" +
29+
" INNER JOIN grp ON grp.id=gh.grp_id AND grp.grp_name=?"
3130

3231
dbConn, err := GetDbConn("nodata.host")
3332
if err != nil {
3433
log.Println("db.get_conn error, host", err)
3534
return hosts
3635
}
3736

38-
rows, err := dbConn.Query(q)
37+
rows, err := dbConn.Query(sqlStatement, now, now, grpName)
3938
if err != nil {
4039
log.Println("[ERROR]", err)
4140
return hosts

0 commit comments

Comments
 (0)