How Can PVS-Studio Help in the Detection of Vulnerabilities?

PVS-Studio is a Tool that Prevents not Only Bugs, but also Vulnerabilities

Later in the article I will tell how we came to this conclusion. But first, I would like to say a few words about PVS-Studio itself.


In the case that you are well aware of the terminology, and know the differences between CVE and CWE as well as their similarities, you may skip this section. Still, I suggest that everybody else to take a look at it, so it will be easier to understand the topic in the future.

PVS-Studio: A Different Point of View


Historically, we have positioned PVS-Studio as a tool to search for errors. In the articles about our project analyses, we have always used corresponding terminology: a bug, an error, a typo. It’s clear that different errors have different levels of severity: there may be some code fragments that contain redundant or misleading code, but there are some errors that cause the whole system to crash at 5 in the morning every third day. Everything was clear, this concept didn’t go any further for a long time — errors were just errors.

CVE Bases

  • Search of CVE in a certain product;
  • Viewing statistics of appearance/fixes of vulnerabilities;
  • Viewing various data tables, in one or another way related to CVE (for example, rating of companies, in whose products was the largest number of vulnerabilities found);
  • And with more besides.

Some CVE that Could Have Been Found Using PVS-Studio

I am writing this article to demonstrate that the PVS-Studio analyzer can protect an application from vulnerabilities (at least, from some of them).


static int devzvol_readdir(....)
char *ptr;
ptr = strchr(ptr + 1, '/') + 1;
sdev_iter_datasets(dvp, ZFS_IOC_DATASET_LIST_NEXT, ptr);

Network Audio System

Network Audio System (NAS) — network-transparent, client-server audio transport system, whose source code is available on SourceForge. NAS works on Unix and Microsoft Windows.

if (NasConfig.DoDaemon) { /* daemons use syslog */
openlog("nas", LOG_PID, LOG_DAEMON);
syslog(LOG_DEBUG, buf);
} else {
errfd = stderr;
void syslog(int priority, const char *format, ...);
syslog(LOG_DEBUG, "%s", buf);

Ytnef (Yerase’s TNEF Stream Reader)

Ytnef — an open source program available on GitHub. It is designed to decode the TNEF streams, created in Outlook, for example.

vl->data = calloc(vl->size, sizeof(WORD));
temp_word = SwapWord((BYTE*)d, sizeof(WORD));
memcpy(vl->data, &temp_word, vl->size);


typedef char my_bool;
check_scramble(const char *scramble_arg, const char *message,
const uint8 *hash_stage2)
return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE);


static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx,
bool isRsa,
SSLBuffer signedParams,
uint8_t *signature,
UInt16 signatureLen)
OSStatus err;
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
if ((err =, &hashOut)) != 0)
goto fail;
return err;
  • V779 Unreachable code detected. It is possible that an error is present
  • unreachable code: as the second goto runs without a condition, the code following it won’t get executed.

Effective Use of Static Analysis

The aim of this article, as I mentioned earlier, is to show that the PVS-Studio analyzer successfully detects vulnerabilities. The approach chosen to achieve this objective is the demonstration that the analyzer finds some well-known vulnerabilities. The material was necessary to confirm the fact that it is possible to search for vulnerabilities using static analysis.


I hope I was able to show that:

  • PVS-Studio successfully copes not only with the detection of errors in the code, but with CWE and CVE as well.

Additional Links



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store