To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
A round of applause to the Tor project

A round of applause to the Tor project

May 12, 2017
Author:

My congratulations to the authors of the Tor project. I didn't manage to find any errors after the analysis by PVS-Studio static code analyzer. We write such words very rarely, so the authors may really be proud. They do deserve a medal for the high-quality code.

0507_Tor_recheck/image1.png

This is not the first time when we check Tor using PVS-Studio analyzer. The previous check was in 2012, after that I wrote a small post: "Security, security! But do you test it?" Interesting enough, 5 years ago I could find errors, but now they are not there.

Over the past 5 years we have significantly developed the diagnostic capabilities of PVS-Studio, and it learned to identify new patterns of errors, such as memory leaks, dead code, incorrect processing of the strings of BSTR type and much more. We easily find error in the code of such projects as GCC, LLVM, C++ REST SDK, GDB, Qt, Chromium, Linux kernel (see the list of articles). But we couldn't write anything about errors in Tor!

What does it show? The authors of the project started taking the quality of the code very seriously.

There were also cases when we didn't find any errors first, but when the analyzer became more powerful, we managed to find them. This is the first case, when we used to detect errors, but now they are not. Tor developers did a really great job! They are really an example for other programmers.

A couple of words about the check itself. We checked the latest version of the Tor source code at the time of writing this article. We used PVS-Studio, version 6.15 for the analysis. The analyzer issued a certain number of warnings, but they aren't very useful, as these are mostly false positives. Having studies the report, I noted down 9 patterns of false positives, that will help us improve the analyzer. It turned out that it wasn't the check of Tor project, but rather the additional testing of PVS-Studio.

As I have said, there were some warnings, which weren't really false positives, but there is no real use in them. A simple example:

ssize_t read_all(...., size_t count, ....)
{
  ....
  if (count > SIZE_T_CEILING || count > SSIZE_MAX) {

The analyzer issues a warning: V590 Consider inspecting this expression. The expression is excessive or contains a misprint. util.c 2116

Let's take a look after expanding the macros:

if (count > ((size_t)(0x7fffffffffffffffL -16)) ||
    count > 0x7fffffffffffffffL) {

Yes, the code is redundant: the second comparison can be removed. However, it's clear that there is no need to fix this code, because this check may be useful with other values of the constants. Which means that it is a false positive, but we don't know how to teach the analyzer to ignore such fragments.

There are some meaningful warnings, but they aren't enough to write an article with the title "Bugs in Tor project". One of such cases:

const char *err = strchr(cp, ':')+2;
tor_assert(err);

The assert would never work. Even if the function strchr returns NULL, then the pointer err will store an invalid value ((char *)2), but it won't be NULL. It would be correct to write the following:

const char *err = strchr(cp, ':');
tor_assert(err);
err += 2;

However, as I understand, the function strchr will never return NULL, and the check is written just in case.

I could note just one warning out of all of them, which indicates an error. Let's consider the following code fragment:

static time_t
edge_of_accounting_period_containing(time_t now, int get_end)
{
  ....
  case UNIT_MONTH: {
    if (tm.tm_mday < cfg_start_day ||
        (tm.tm_mday < cfg_start_day && before)) {
      --tm.tm_mon;
    }
  ....
}

PVS-Studio warning: V686 A pattern was detected: (tm.tm_mday < cfg_start_day) || ((tm.tm_mday < cfg_start_day) && ...). The expression is excessive or contains a logical error. hibernate.c 333

The check can be simplified to:

if (tm.tm_mday < cfg_start_day) {

Perhaps, there is a typo or a logical error in this condition.

There is nothing more I could write about. There is a change that I could have inadvertently skipped some error, but this wouldn't change the overall picture. Checking other open source projects, we find dozens and even hundreds errors. At this point we have more than 10 000 bugs in our collection, found in various open source projects. I would be happy to find some in Tor, and then describe 20-30 of the most interesting of them, but I couldn't. Once more, the authors of the project did a great job.

Popular related articles
The way static analyzers fight against false positives, and why they do it

Date: 03.20.2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Free PVS-Studio for those who develops open source projects

Date: 12.22.2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
Appreciate Static Code Analysis!

Date: 10.16.2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: 07.31.2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
The Last Line Effect

Date: 05.31.2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: 10.22.2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The Evil within the Comparison Functions

Date: 05.19.2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Static analysis as part of the development process in Unreal Engine

Date: 06.27.2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept