New Defects reported by Coverity Scan for git
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jeff, I suppose you are the admin of git on scan.coverity, or knows him/her, perhaps we can add a model for xmalloc to suppress these "null pointer deferences" reports? We are sure xmalloc() never returns NULL. Qemu did it [1] and it looks simple.. I think something like this would do
void *xmalloc(size_t size)
{
void *mem = malloc(size);
if (!mem) __coverity_panic__();
return mem;
}
---------- Forwarded message ----------
From: <[email protected]>
Date: Fri, Jul 31, 2015 at 5:54 PM
Subject: New Defects reported by Coverity Scan for git
To: [email protected]
_______________________________________________________________________________________________________
*** CID 1313836: Null pointer dereferences (FORWARD_NULL) /rerere.c: 150 in find_rerere_dir()
144 return NULL; /* BUG */
145 pos = sha1_pos(sha1, rerere_dir, rerere_dir_nr,rerere_dir_sha1);
146 if (pos < 0) {
147 rr_dir = xmalloc(sizeof(*rr_dir)); 148 hashcpy(rr_dir->sha1, sha1); 149 rr_dir->status_nr = rr_dir->status_alloc = 0;
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 1313836: Null pointer dereferences (
FORWARD_NULL)
Assigning: "rr_dir->status" = "NULL".
150 rr_dir->status = NULL;
151 pos = -1 - pos;
152
153 /* Make sure the array is big enough ... */
154 ALLOC_GROW(rerere_dir, rerere_dir_nr + 1,rerere_dir_alloc);
155 /* ... and add it in. */
** CID 1313835: Null pointer dereferences (FORWARD_NULL) /builtin/fetch.c: 795 in prune_refs()
Signature · 1 line
Duy
Quoted 6 lines · Duy Nguyen
Jeff, I suppose you are the admin of git on scan.coverity, or knows him/her, perhaps we can add a model for xmalloc to suppress these "null pointer deferences" reports? We are sure
xmalloc()never returns NULL. Qemu did it [1] and it looks simple.. I think something like this would do
Quoted 9 lines
void *xmalloc(size_t size)
{ void *mem = malloc(size); if (!mem) __coverity_panic__(); return mem; }
Taking just that excerpt doesn't work. Upload fails with "modeling_file.c", line 12: error #20:
identifier "malloc" is undefined
void *mem = malloc(size);
I'll look into your reference[1] a bit more and try to follow it as a guidance.
Quoted 35 lines
---------- Forwarded message ----------
From: <[email protected]>
Date: Fri, Jul 31, 2015 at 5:54 PM
Subject: New Defects reported by Coverity Scan for git
To: [email protected]_______________________________________________________________________________________________________
*** CID 1313836: Null pointer dereferences (FORWARD_NULL) /rerere.c: 150 infind_rerere_dir()
144 return NULL; /* BUG */
145 pos = sha1_pos(sha1,rerere_dir,rerere_dir_nr,rerere_dir_sha1);
146 if (pos < 0) {147 rr_dir = xmalloc(sizeof(*rr_dir)); 148 hashcpy(rr_dir->sha1, sha1); 149 rr_dir->status_nr = rr_dir->status_alloc = 0;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 1313836: Null pointer dereferences (
FORWARD_NULL)
Assigning: "rr_dir->status" = "NULL".150
rr_dir->status= NULL;
151 pos = -1 - pos;
152
153 /* Make sure the array is big enough ... */
154 ALLOC_GROW(rerere_dir,rerere_dir_nr+ 1,rerere_dir_alloc);
155 /* ... and add it in. */** CID 1313835: Null pointer dereferences (
FORWARD_NULL) /builtin/fetch.c: 795 inprune_refs()
--
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Stefan Beller
Quoted 6 lines · Duy Nguyen
Jeff, I suppose you are the admin of git on scan.coverity, or knows him/her, perhaps we can add a model for xmalloc to suppress these "null pointer deferences" reports? We are sure
xmalloc()never returns NULL. Qemu did it [1] and it looks simple.. I think something like this would doQuoted 9 lines
void *xmalloc(size_t size)
{ void *mem = malloc(size); if (!mem) __coverity_panic__(); return mem; }
Quoted 6 lines
Taking just that excerpt doesn't work. Upload fails with "
modeling_file.c", line 12: error #20:
identifier "malloc" is undefined
void *mem = malloc(size);I'll look into your reference[1] a bit more and try to follow it as a guidance.
So I put in these lines into the modeling file:
void *malloc(size_t);
void *calloc(size_t, size_t);
void *realloc(void *, size_t);
void free(void *);
void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
if (!ret) __coverity_panic__();
return ret;
}
void *xmalloc(size_t size)
{
void *mem = malloc(size);
if (!mem) __coverity_panic__();
return mem;
}
void xcalloc(size_t num, size_t size)
{
void *ret = calloc(num, size);
if (!ret) __coverity_panic__();
return ret;
}
and there seem to be 42 new defects and 20 fixed defects by the modeling of memory allocations. We'd need to check if coverity understood the modeling as we intended it. Looking at the first few issues, they seem to be correctly finding
leaks.
Quoted 37 lines
Quoted 37 lines
---------- Forwarded message ----------
From: <[email protected]>
Date: Fri, Jul 31, 2015 at 5:54 PM
Subject: New Defects reported by Coverity Scan for git
To: [email protected]_______________________________________________________________________________________________________
*** CID 1313836: Null pointer dereferences (FORWARD_NULL) /rerere.c: 150 infind_rerere_dir()
144 return NULL; /* BUG */
145 pos = sha1_pos(sha1,rerere_dir,rerere_dir_nr,rerere_dir_sha1);
146 if (pos < 0) {147 rr_dir = xmalloc(sizeof(*rr_dir)); 148 hashcpy(rr_dir->sha1, sha1); 149 rr_dir->status_nr = rr_dir->status_alloc = 0;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 1313836: Null pointer dereferences (
FORWARD_NULL)
Assigning: "rr_dir->status" = "NULL".150
rr_dir->status= NULL;
151 pos = -1 - pos;
152
153 /* Make sure the array is big enough ... */
154 ALLOC_GROW(rerere_dir,rerere_dir_nr+ 1,rerere_dir_alloc);
155 /* ... and add it in. */** CID 1313835: Null pointer dereferences (
FORWARD_NULL) /builtin/fetch.c: 795 inprune_refs()
--
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html