git/list[1] front-page[2] threads[3] people[4] search[5] about
 

scan.coverity: improve the modeling file of git.git

From
Stefan Beller <stefanbeller@gmail.com>
Date
Jul 20, 2014, 21:44 UTC
Message-ID
<53CC3855.8050500@gmail.com>
Hi Sam, John and Jeff,

I'm writing to you, as you're listed as the administrator of the git.git project on scan.coverity.com

We're currently seeing lots of false positives as the xmalloc/xrealloc function is handled not properly by coverity. There are lots of errors "Allocation too small for type"

Quoting (starting linenumbers are code) from some xrealloc ocurrence:
 95void *xrealloc(void *ptr, size_t size)
 96{
 97        void *ret;
 98
 99        memory_limit_check(size);
100        ret = realloc(ptr, size);
1. Condition "!ret", taking true branch   
2. Condition "!size", taking true branch
101        if (!ret && !size)
   
3. buffer_alloc: "realloc(void *, size_t)" which allocates 1 bytes based on "1UL".   
4. var_assign: Assigning: "ret" = storage allocated by "realloc(ptr, 1UL)".
102                ret = realloc(ptr, 1);
   
5. Condition "!ret", taking false branch
103        if (!ret) {
104                try_to_free_routine(size);
105                ret = realloc(ptr, size);
106                if (!ret && !size)
107                        ret = realloc(ptr, 1);
108                if (!ret)
109                        die("Out of memory, realloc failed");
110        }
   
6. return_dbuffer: Returning allocated array "ret".

111 return ret; 112}

However I have reviewed the function and I'd be pretty sure it would work as expected. According to https://scan.coverity.com/tune we can upload a modelling file, which will allow us to supress such false positive errors. I believe we'd need to put in the modelling file something like:

	// coverity[+alloc]
	void *xrealloc(void *ptr, size_t size);

and that should do. We'd not need to modify the git.git sources, but just add such a declaration to the modelling file.

Does anyone of you administrators want to experiment with that?

Cheers, Stefan

Next: Jeff King
Message 1 of 2 in “scan.coverity: improve the modeling file of git.git”
  1. Stefan BellerJul 20, 2014
  2. Jeff KingJul 22, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.