Our application is written in VB.Net. On scanning our application in HP Fortify, Null Dereference issue was pointed at the only the For Each ... Next loop in the few pages. What could be the reason the Null Reference is shown only at the For each loop. At all places where the For Each loop is used in the application the null dereference is pointing to the "Next" of the For Each loop. Please help resolve this scan issue. A sample code snippet from our application is below.
If Request.QueryString("mode") IsNot Nothing Then
mode = Request.QueryString("mode")
End If
.
.
.
For Each col In gridTemp.Columns
Select Case col.HeaderText
Case "ID"
col.Visible = IIf(mode = "Admin", True, False)
Case "Name"
col.Visible = IIf(mode = "Admin", True, False)
Case "Balance"
col.Visible = IIf(mode = "Admin", False, True)
Case "Dues"
col.Visible = IIf(mode = "Admin", True, False)
Case "Contact"
col.Visible = IIf(mode = "Admin", False, True)
End Select
Next
The only way we've found to get around this is to convert for each loops into for loops. In this case, try using something like
For I as Integer = 0 to gridTemp.Columns.Count - 1
Dim col as Column(i)
Select Case col.HeaderText
Case "ID"
col.Visible = IIf(mode = "Admin", True, False)
Case "Name"
col.Visible = IIf(mode = "Admin", True, False)
Case "Balance"
col.Visible = IIf(mode = "Admin", False, True)
Case "Dues"
col.Visible = IIf(mode = "Admin", True, False)
Case "Contact"
col.Visible = IIf(mode = "Admin", False, True)
End Select
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With