JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc


More Warnings

We take a brief look at the other warnings issued by the analysis.

Tainted Path Warning

The example code prompts the user for a file name, then uses the resulting name to open a file and write a value into it. This could cause significant problems if, for example, a malicious user provided the name of an important system file such as /etc/passwd.

CodeSonar can detect the flow of information from a tainted source (such as user input or an untrusted database) and identify cases where that information is used in a context where values must be trustworthy. In this particular case, CodeSonar detects that the program using user input in a context where a trusted file path is required, so it issues a Tainted Path (C#) warning.

  1. Click the cs-BasicProj analysis 1 link in the page breadcrumbs.

    screenshot fragment: Next link

    The Analysis page will open.
  2. Click the table entry for the "Tainted Path (C#)" warning.
  3. The Warning Report will open.
    It has the same general structure as the Null Pointer Dereference (C#) warning that you have just looked at.
  4. Expand the warning details section.

    screenshot fragment: warning details for Tainted Path warning

    The "Tainted Path (C#)" warning class is associated with entries in the OWASP Top Ten Application Security Risks in both the most recent (2021) and previous (2017) versions.
  5. If you are interested, click on the OWASP-2021:A3 link to read the corresponding entry on the OWASP website. The entry will open in a new tab, and includes:
  6. Click the Jump to warning location ↓ link or scroll down (if necessary) to view the warning description box.

    screenshot fragment: warning description box for Tainted Path warning

    The warning description box identifies the key elements of the issue:

Two Condition Warnings

BasicCsharp.cs contains two different examples of warnings about IF statement conditions. These warnings could indicate mistaken assumptions by the programmer, logic errors in the program, or both.

  1. Click the cs-BasicProj analysis 1 link to navigate back to the Analysis page.
  2. Click the table entry for the "Empty Branch Statement (C#)" warning.
  3. Navigate or scroll to the warning description box.

    screenshot fragment: warning description box for Exmpty Branch Statement warning

    The issue here is that line 11 represents a complete IF statement: if (args.length > 0);

    Both branches of this IF statement are empty, so it has no effect on the program outcome. Its presence in the program is therefore at best useless, and at worst actively misleading. In particular, the indentation on line 12 encourages readers to regard this line as the TRUE branch of an IF statement governed by the condition on line 11.

    The programmer probably did not intend to write the program this way. There are two likely cases.

  4. Click the cs-BasicProj analysis 1 link to navigate back to the Analysis page.
  5. Click the table entry for the "Redundant Condition (C#)" warning.
  6. Navigate or scroll to the warning description box.

    screenshot fragment: warning description box for Redundant Condition warning

    The problem here is that the IF statement condition always evaluates to TRUE: two distinct objects will always compare unequal with !=. This means that the program outcome would be exactly the same if we removed the IF header on line 16 and left the assignment on line 17.

    Redundant condition warnings typically indicate one of the following.

Debug Warning

The last of the warnings in BasicCsharp.cs is an instance of "Deug Warning (C#)".

  1. Click the cs-BasicProj analysis 1 link to navigate back to the Analysis page.
  2. Click the table entry for the "Debug Warning (C#)" warning.
  3. Navigate or scroll to the warning description box on line 23.

    screenshot fragment: warning description box for Generic Exception Handler warning

    This warning suggests that the call to Console.WriteLine() be replaced with a logging method.

    Replacing with a logging method isn't quite the right resolution here: the code is using Console.WriteLine() to prompt the user for input rather than to perform some other task (such as print-based debugging). We have a number of potential resolution options.

Next

 

To report problems with this documentation, please visit https://support.codesecure.com/.