github-vet / github-vet/rangeloop-pointer-findings
databrokerglobal/dxc: datasources/host-check.go; 66 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [databrokerglobal/dxc](https://www.github.com/databrokerglobal/dxc) at [datasources/host-check.go](https://github.com/databrokerglobal/dxc/blob/b30274fcdbfe768b4350f346194abb54776009a0/datasources/host-check.go#L29-L94)
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/databrokerglobal/dxc/blob/b30274fcdbfe768b4350f346194abb54776009a0/datasources/host-check.go#L29-L94)
Click here to show the 66 line(s) of Go which triggered the analyzer.
```go
for _, datasource := range *datasources {
notfounderror := errors.New("No file found. Please check filename or path")
if datasource.Host != "" && datasource.Host != "N/A" && datasource.Name != "" {
if datasource.Protocol == "LOCAL" {
path := strings.Replace(datasource.Host, "file://", "", -1)
_, notfounderror = os.Stat(path)
} else if datasource.Type == "API" || datasource.Protocol == "HTTP" || datasource.Protocol == "HTTPS" {
// note we are checking API HOST also as protocol used is HTTP/HTTPS for those datasources
_, notfounderror = http.Get(datasource.Host)
} else if datasource.Protocol == "FTP" || datasource.Protocol == "FTPS" {
filename := path.Base(datasource.Host)
// get server address and path of file
server, path, err := getFtpServer(datasource.Protocol, datasource.Host, filename)
// get client of ftp server
client, err := ftp.Dial(server)
if err == nil {
// now connect to server
err := client.Login(datasource.Ftpusername, datasource.Ftppassword)
// Close connection
defer client.Quit()
if err == nil {
// change directory to path
client.ChangeDir(path)
// get file entry
entries, _ := client.List(filename)
if len(entries) > 0 {
notfounderror = nil
}
}
}
} else if datasource.Protocol == "SFTP" {
filename := path.Base(datasource.Host)
// get server address and path of file
server, path, err := getFtpServer(datasource.Protocol, datasource.Host, filename)
// get client of ftp server
config := &ssh.ClientConfig{
User: datasource.Ftpusername,
Auth: []ssh.AuthMethod{
ssh.Password(datasource.Ftppassword),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
//Ciphers: []string{"3des-cbc", "aes256-cbc", "aes192-cbc", "aes128-cbc"},
}
conn, err := ssh.Dial("tcp", server, config)
if err == nil {
client, err := sftp.NewClient(conn)
// Close connection
defer client.Close()
defer conn.Close()
if err == nil {
// change directory to path
cwd, err := client.ReadDir(path) // []os.FileInfo
if err == nil {
if contains(cwd, filename) {
notfounderror = nil
}
}
}
}
} else {
// future implementation dataosurce with streams or other protocols
}
datasource.Available = notfounderror == nil
database.DBInstance.UpdateDatasource(&datasource)
}
}
```
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 {UpdateDatasource 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: b30274fcdbfe768b4350f346194abb54776009a0
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.