blob: 421d54d4191d71a770b16fcf628e187b88a8a2aa [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 Heimes8cda5e62013-07-26 18:00:12 +020022#define assert(op) /* empty */
Christian Heimesb911cfd2013-07-23 01:31:15 +020023typedef int sdigit;
24typedef long Py_ssize_t;
Christian Heimes8cda5e62013-07-26 18:00:12 +020025typedef long long PY_LONG_LONG;
Christian Heimesb911cfd2013-07-23 01:31:15 +020026typedef unsigned short wchar_t;
27typedef struct {} PyObject;
28typedef struct {} grammar;
Christian Heimesb911cfd2013-07-23 01:31:15 +020029typedef struct {} DIR;
30typedef struct {} RFILE;
31
Christian Heimesb911cfd2013-07-23 01:31:15 +020032/* Python/pythonrun.c
33 * resourece leak false positive */
34
35void Py_FatalError(const char *msg) {
36 __coverity_panic__();
37}
38
39/* Objects/longobject.c
40 * NEGATIVE_RETURNS false positive */
41
Christian Heimesb911cfd2013-07-23 01:31:15 +020042static PyObject *get_small_int(sdigit ival)
43{
Christian Heimes8cda5e62013-07-26 18:00:12 +020044 /* Never returns NULL */
Christian Heimesb911cfd2013-07-23 01:31:15 +020045 PyObject *p;
Christian Heimes8cda5e62013-07-26 18:00:12 +020046 assert(p != NULL);
Christian Heimesb911cfd2013-07-23 01:31:15 +020047 return p;
48}
49
Christian Heimes8cda5e62013-07-26 18:00:12 +020050PyObject *PyLong_FromLong(long ival)
51{
52 PyObject *p;
53 int maybe;
54
55 if ((ival >= -5) && (ival < 257 + 5)) {
56 p = get_small_int(ival);
57 assert(p != NULL);
58 return p;
59 }
60 if (maybe)
61 return p;
62 else
63 return NULL;
64}
65
66PyObject *PyLong_FromLongLong(PY_LONG_LONG ival)
67{
68 return PyLong_FromLong((long)ival);
69}
70
71PyObject *PyLong_FromSsize_t(Py_ssize_t ival)
72{
73 return PyLong_FromLong((long)ival);
74}
75
Christian Heimesb911cfd2013-07-23 01:31:15 +020076/* tainted sinks
77 *
78 * Coverity considers argv, environ, read() data etc as tained.
79 */
80
81PyObject *PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
82{
83 __coverity_tainted_data_sink__(filename);
84 return NULL;
85}
86
87/* Python/fileutils.c */
Victor Stinnerf6a271a2014-08-01 12:28:48 +020088wchar_t *Py_DecodeLocale(const char* arg, size_t *size)
Christian Heimesb911cfd2013-07-23 01:31:15 +020089{
90 wchar_t *w;
91 __coverity_tainted_data_sink__(arg);
92 __coverity_tainted_data_sink__(size);
93 return w;
94}
95
96/* Parser/pgenmain.c */
97grammar *getgrammar(char *filename)
98{
99 grammar *g;
100 __coverity_tainted_data_sink__(filename);
101 return g;
102}
103
104/* Python/marshal.c */
105
106static Py_ssize_t r_string(char *s, Py_ssize_t n, RFILE *p)
107{
108 __coverity_tainted_string_argument__(s);
109 return 0;
110}
111
112static long r_long(RFILE *p)
113{
114 long l;
115 unsigned char buffer[4];
116
117 r_string((char *)buffer, 4, p);
118 __coverity_tainted_string_sanitize_content__(buffer);
119 l = (long)buffer;
120 return l;
121}
122
123/* Coverity doesn't understand that fdopendir() may take ownership of fd. */
124
125DIR *fdopendir(int fd) {
126 DIR *d;
127 if (d) {
128 __coverity_close__(fd);
129 }
130 return d;
131}
132