Skip to content

Commit a1e38c3

Browse files
committed
Remove unnecessary imports and add returns
1 parent eccde3f commit a1e38c3

File tree

3 files changed

+15
-193
lines changed

3 files changed

+15
-193
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
edges
22
| ImproperLdapAuth.go:18:18:18:24 | selection of URL | ImproperLdapAuth.go:18:18:18:32 | call to Query |
33
| ImproperLdapAuth.go:18:18:18:32 | call to Query | ImproperLdapAuth.go:28:23:28:34 | bindPassword |
4-
| ImproperLdapAuth.go:80:18:80:19 | "" | ImproperLdapAuth.go:90:23:90:34 | bindPassword |
4+
| ImproperLdapAuth.go:87:18:87:19 | "" | ImproperLdapAuth.go:97:23:97:34 | bindPassword |
55
nodes
66
| ImproperLdapAuth.go:18:18:18:24 | selection of URL | semmle.label | selection of URL |
77
| ImproperLdapAuth.go:18:18:18:32 | call to Query | semmle.label | call to Query |
88
| ImproperLdapAuth.go:28:23:28:34 | bindPassword | semmle.label | bindPassword |
9-
| ImproperLdapAuth.go:80:18:80:19 | "" | semmle.label | "" |
10-
| ImproperLdapAuth.go:90:23:90:34 | bindPassword | semmle.label | bindPassword |
9+
| ImproperLdapAuth.go:87:18:87:19 | "" | semmle.label | "" |
10+
| ImproperLdapAuth.go:97:23:97:34 | bindPassword | semmle.label | bindPassword |
1111
subpaths
1212
#select
1313
| ImproperLdapAuth.go:28:23:28:34 | bindPassword | ImproperLdapAuth.go:18:18:18:24 | selection of URL | ImproperLdapAuth.go:28:23:28:34 | bindPassword | LDAP binding password depends on a $@. | ImproperLdapAuth.go:18:18:18:24 | selection of URL | user-provided value |
14-
| ImproperLdapAuth.go:90:23:90:34 | bindPassword | ImproperLdapAuth.go:80:18:80:19 | "" | ImproperLdapAuth.go:90:23:90:34 | bindPassword | LDAP binding password depends on a $@. | ImproperLdapAuth.go:80:18:80:19 | "" | user-provided value |
14+
| ImproperLdapAuth.go:97:23:97:34 | bindPassword | ImproperLdapAuth.go:87:18:87:19 | "" | ImproperLdapAuth.go:97:23:97:34 | bindPassword | LDAP binding password depends on a $@. | ImproperLdapAuth.go:87:18:87:19 | "" | user-provided value |

go/ql/test/experimental/CWE-287/ImproperLdapAuth.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ func bad(w http.ResponseWriter, req *http.Request) (interface{}, error) {
2020
// Connect to the LDAP server
2121
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
2222
if err != nil {
23-
log.Fatalf("Failed to connect to LDAP server: %v", err)
23+
return fmt.Errorf("Failed to connect to LDAP server: %v", err), err
2424
}
2525
defer l.Close()
2626

2727
// BAD: user input is not sanetized
2828
err = l.Bind(bindDN, bindPassword)
2929
if err != nil {
30-
log.Fatalf("LDAP bind failed: %v", err)
30+
return fmt.Errorf("LDAP bind failed: %v", err), err
3131
}
32+
return nil, nil
3233
}
3334

3435
func good1(w http.ResponseWriter, req *http.Request) (interface{}, error) {
@@ -40,7 +41,7 @@ func good1(w http.ResponseWriter, req *http.Request) (interface{}, error) {
4041
// Connect to the LDAP server
4142
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
4243
if err != nil {
43-
log.Fatalf("Failed to connect to LDAP server: %v", err)
44+
return fmt.Errorf("Failed to connect to LDAP server: %v", err), err
4445
}
4546
defer l.Close()
4647

@@ -50,6 +51,10 @@ func good1(w http.ResponseWriter, req *http.Request) (interface{}, error) {
5051
if !hasEmptyInput {
5152
l.Bind(bindDN, bindPassword)
5253
}
54+
if err != nil {
55+
return fmt.Errorf("LDAP bind failed: %v", err), err
56+
}
57+
return nil, nil
5358
}
5459

5560
func good2(w http.ResponseWriter, req *http.Request) (interface{}, error) {
@@ -61,14 +66,16 @@ func good2(w http.ResponseWriter, req *http.Request) (interface{}, error) {
6166
// Connect to the LDAP server
6267
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
6368
if err != nil {
64-
log.Fatalf("Failed to connect to LDAP server: %v", err)
69+
return fmt.Errorf("Failed to connect to LDAP server: %v", err), err
6570
}
6671
defer l.Close()
6772

6873
// GOOD : bindPassword is not empty
6974
if bindPassword != "" {
7075
l.Bind(bindDN, bindPassword)
76+
return nil, err
7177
}
78+
return nil, nil
7279
}
7380

7481
func bad2(req *http.Request) {

go/vendor/gopkg.in/ldap.v2/stub.go

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)