blob: 288b6302474749a6eddee37c86283c0c8b8aa507 [file] [log] [blame]
Christian Heimesb911cfd2013-07-23 01:31:15 +02001/* Coverity Scan model
2 *
3 * This is a modeling file for Coverity Scan. Modeling helps to avoid false
4 * positives.
5 *
6 * - A model file can't import any header files.
7 * - Therefore only some built-in primitives like int, char and void are
8 * available but not wchar_t, NULL etc.
9 * - Modeling doesn't need full structs and typedefs. Rudimentary structs
10 * and similar types are sufficient.
11 * - An uninitialized local pointer is not an error. It signifies that the
12 * variable could be either NULL or have some data.
13 *
14 * Coverity Scan doesn't pick up modifications automatically. The model file
15 * must be uploaded by an admin in the analysis settings of
16 * http://scan.coverity.com/projects/200
Christian Heimesb911cfd2013-07-23 01:31:15 +020017 */
18
Christian Heimesb911cfd2013-07-23 01:31:15 +020019/* dummy definitions, in most cases struct fields aren't required. */
20
21#define NULL (void *)0
Christian Heimesb911cfd2013-07-23 01:31:15 +020022typedef int sdigit;
23typedef long Py_ssize_t;
24typedef unsigned short wchar_t;
25typedef struct {} PyObject;
26typedef struct {} grammar;
Christian Heimesb911cfd2013-07-23 01:31:15 +020027typedef struct {} DIR;
28typedef struct {} RFILE;
29
Christian Heimesb911cfd2013-07-23 01:31:15 +020030/* Python/pythonrun.c
31 * resourece leak false positive */
32
33void Py_FatalError(const char *msg) {
34 __coverity_panic__();
35}
36
37/* Objects/longobject.c
38 * NEGATIVE_RETURNS false positive */
39
40static PyObject small_ints[257 + 5];
41
42static PyObject *get_small_int(sdigit ival)
43{
44 PyObject *p;
45 if (((ival + 5) >= 0) && ((ival + 5) < 257 + 5)) {
46 return &small_ints[ival + 5];
47 }
48 return p;
49}
50
51/* tainted sinks
52 *
53 * Coverity considers argv, environ, read() data etc as tained.
54 */
55
56PyObject *PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
57{
58 __coverity_tainted_data_sink__(filename);
59 return NULL;
60}
61
62/* Python/fileutils.c */
63wchar_t *_Py_char2wchar(const char* arg, size_t *size)
64{
65 wchar_t *w;
66 __coverity_tainted_data_sink__(arg);
67 __coverity_tainted_data_sink__(size);
68 return w;
69}
70
71/* Parser/pgenmain.c */
72grammar *getgrammar(char *filename)
73{
74 grammar *g;
75 __coverity_tainted_data_sink__(filename);
76 return g;
77}
78
79/* Python/marshal.c */
80
81static Py_ssize_t r_string(char *s, Py_ssize_t n, RFILE *p)
82{
83 __coverity_tainted_string_argument__(s);
84 return 0;
85}
86
87static long r_long(RFILE *p)
88{
89 long l;
90 unsigned char buffer[4];
91
92 r_string((char *)buffer, 4, p);
93 __coverity_tainted_string_sanitize_content__(buffer);
94 l = (long)buffer;
95 return l;
96}
97
98/* Coverity doesn't understand that fdopendir() may take ownership of fd. */
99
100DIR *fdopendir(int fd) {
101 DIR *d;
102 if (d) {
103 __coverity_close__(fd);
104 }
105 return d;
106}
107