【发布时间】:2020-08-29 11:30:29
【问题描述】:
我有以下代码,如果我正确阅读了有关此主题的其他主题,则不应导致 Veracode 扫描标记 CWE 117,但确实如此。 Java/C# 还有其他一些“答案”,但我没有找到任何适用于 VB.NET 的东西。
我的代码是这样的:
Public Function WriteToEventLog(ByVal Entry As String, Optional ByVal AppName As String = "adCoreLibrary", Optional ByVal EventType As EventLogEntryType = Nothing, Optional ByVal LogName As String = "Application", Optional ByVal EventID As Integer = 0, Optional ByVal TaskCategory As TaskCategory = 0) As Boolean
Dim objEventLog As New EventLog()
Try
' We will try and create our own event log but if not, use the optional default
If Not EventLog.SourceExists(AppName) Then
EventLog.CreateEventSource(AppName, LogName)
End If
' Initialise event log
objEventLog.BeginInit()
' Set the source
objEventLog.Source = AppName
' Write entry
If Entry IsNot Nothing Then
' THE FOLLOWING LINE IS BEING FLAGGED AS CWE-117 NON-COMPLIANT
objEventLog.WriteEntry(Entry.Replace(vbLf, "_"c).Replace(vbCr, "_"c).Replace(vbTab, "_"c), EventType, EventID, CShort(TaskCategory))
End If
' End initialisation
objEventLog.EndInit()
Return True
Exit Function
Catch ex As Exception
If CType(My.Settings.adLogMode, LogMode) <> adCoreLogging.LogMode.Empty Then
My.Application.Log.WriteEntry("An error occured when trying to write to the Windows Event Log: " & ex.Message.ToString)
Return False
End If
Finally
End Try
' If we get here, we've had a problem
Return False
End Function
谁能告诉我我在这里做错了什么?
【问题讨论】:
-
您是否尝试过应用 Java/C# 答案之一?
-
这些答案让我添加了 Replace(vbLf, ""c).Replace(vbCr, ""c).Replace(vbTab, "_"c) 但那似乎没有补救。另外,我不擅长阅读 Java/C#
标签: vb.net veracode secure-coding