1 | n/a | /* Coverity Scan model |
---|
2 | n/a | * |
---|
3 | n/a | * This is a modeling file for Coverity Scan. Modeling helps to avoid false |
---|
4 | n/a | * positives. |
---|
5 | n/a | * |
---|
6 | n/a | * - A model file can't import any header files. |
---|
7 | n/a | * - Therefore only some built-in primitives like int, char and void are |
---|
8 | n/a | * available but not wchar_t, NULL etc. |
---|
9 | n/a | * - Modeling doesn't need full structs and typedefs. Rudimentary structs |
---|
10 | n/a | * and similar types are sufficient. |
---|
11 | n/a | * - An uninitialized local pointer is not an error. It signifies that the |
---|
12 | n/a | * variable could be either NULL or have some data. |
---|
13 | n/a | * |
---|
14 | n/a | * Coverity Scan doesn't pick up modifications automatically. The model file |
---|
15 | n/a | * must be uploaded by an admin in the analysis settings of |
---|
16 | n/a | * http://scan.coverity.com/projects/200 |
---|
17 | n/a | */ |
---|
18 | n/a | |
---|
19 | n/a | /* dummy definitions, in most cases struct fields aren't required. */ |
---|
20 | n/a | |
---|
21 | n/a | #define NULL (void *)0 |
---|
22 | n/a | #define assert(op) /* empty */ |
---|
23 | n/a | typedef int sdigit; |
---|
24 | n/a | typedef long Py_ssize_t; |
---|
25 | n/a | typedef unsigned short wchar_t; |
---|
26 | n/a | typedef struct {} PyObject; |
---|
27 | n/a | typedef struct {} grammar; |
---|
28 | n/a | typedef struct {} DIR; |
---|
29 | n/a | typedef struct {} RFILE; |
---|
30 | n/a | |
---|
31 | n/a | /* Python/pythonrun.c |
---|
32 | n/a | * resource leak false positive */ |
---|
33 | n/a | |
---|
34 | n/a | void Py_FatalError(const char *msg) { |
---|
35 | n/a | __coverity_panic__(); |
---|
36 | n/a | } |
---|
37 | n/a | |
---|
38 | n/a | /* Objects/longobject.c |
---|
39 | n/a | * NEGATIVE_RETURNS false positive */ |
---|
40 | n/a | |
---|
41 | n/a | static PyObject *get_small_int(sdigit ival) |
---|
42 | n/a | { |
---|
43 | n/a | /* Never returns NULL */ |
---|
44 | n/a | PyObject *p; |
---|
45 | n/a | assert(p != NULL); |
---|
46 | n/a | return p; |
---|
47 | n/a | } |
---|
48 | n/a | |
---|
49 | n/a | PyObject *PyLong_FromLong(long ival) |
---|
50 | n/a | { |
---|
51 | n/a | PyObject *p; |
---|
52 | n/a | int maybe; |
---|
53 | n/a | |
---|
54 | n/a | if ((ival >= -5) && (ival < 257 + 5)) { |
---|
55 | n/a | p = get_small_int(ival); |
---|
56 | n/a | assert(p != NULL); |
---|
57 | n/a | return p; |
---|
58 | n/a | } |
---|
59 | n/a | if (maybe) |
---|
60 | n/a | return p; |
---|
61 | n/a | else |
---|
62 | n/a | return NULL; |
---|
63 | n/a | } |
---|
64 | n/a | |
---|
65 | n/a | PyObject *PyLong_FromLongLong(long long ival) |
---|
66 | n/a | { |
---|
67 | n/a | return PyLong_FromLong((long)ival); |
---|
68 | n/a | } |
---|
69 | n/a | |
---|
70 | n/a | PyObject *PyLong_FromSsize_t(Py_ssize_t ival) |
---|
71 | n/a | { |
---|
72 | n/a | return PyLong_FromLong((long)ival); |
---|
73 | n/a | } |
---|
74 | n/a | |
---|
75 | n/a | /* tainted sinks |
---|
76 | n/a | * |
---|
77 | n/a | * Coverity considers argv, environ, read() data etc as tained. |
---|
78 | n/a | */ |
---|
79 | n/a | |
---|
80 | n/a | PyObject *PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) |
---|
81 | n/a | { |
---|
82 | n/a | __coverity_tainted_data_sink__(filename); |
---|
83 | n/a | return NULL; |
---|
84 | n/a | } |
---|
85 | n/a | |
---|
86 | n/a | /* Python/fileutils.c */ |
---|
87 | n/a | wchar_t *Py_DecodeLocale(const char* arg, size_t *size) |
---|
88 | n/a | { |
---|
89 | n/a | wchar_t *w; |
---|
90 | n/a | __coverity_tainted_data_sink__(arg); |
---|
91 | n/a | __coverity_tainted_data_sink__(size); |
---|
92 | n/a | return w; |
---|
93 | n/a | } |
---|
94 | n/a | |
---|
95 | n/a | /* Parser/pgenmain.c */ |
---|
96 | n/a | grammar *getgrammar(const char *filename) |
---|
97 | n/a | { |
---|
98 | n/a | grammar *g; |
---|
99 | n/a | __coverity_tainted_data_sink__(filename); |
---|
100 | n/a | return g; |
---|
101 | n/a | } |
---|
102 | n/a | |
---|
103 | n/a | /* Python/marshal.c */ |
---|
104 | n/a | |
---|
105 | n/a | static Py_ssize_t r_string(char *s, Py_ssize_t n, RFILE *p) |
---|
106 | n/a | { |
---|
107 | n/a | __coverity_tainted_string_argument__(s); |
---|
108 | n/a | return 0; |
---|
109 | n/a | } |
---|
110 | n/a | |
---|
111 | n/a | static long r_long(RFILE *p) |
---|
112 | n/a | { |
---|
113 | n/a | long l; |
---|
114 | n/a | unsigned char buffer[4]; |
---|
115 | n/a | |
---|
116 | n/a | r_string((char *)buffer, 4, p); |
---|
117 | n/a | __coverity_tainted_string_sanitize_content__(buffer); |
---|
118 | n/a | l = (long)buffer; |
---|
119 | n/a | return l; |
---|
120 | n/a | } |
---|
121 | n/a | |
---|
122 | n/a | /* Coverity doesn't understand that fdopendir() may take ownership of fd. */ |
---|
123 | n/a | |
---|
124 | n/a | DIR *fdopendir(int fd) |
---|
125 | n/a | { |
---|
126 | n/a | DIR *d; |
---|
127 | n/a | if (d) { |
---|
128 | n/a | __coverity_close__(fd); |
---|
129 | n/a | } |
---|
130 | n/a | return d; |
---|
131 | n/a | } |
---|
132 | n/a | |
---|
133 | n/a | /* Modules/_datetime.c |
---|
134 | n/a | * |
---|
135 | n/a | * Coverity thinks that the input values for these function come from a |
---|
136 | n/a | * tainted source PyDateTime_DATE_GET_* macros use bit shifting. |
---|
137 | n/a | */ |
---|
138 | n/a | static PyObject * |
---|
139 | n/a | build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag) |
---|
140 | n/a | { |
---|
141 | n/a | PyObject *result; |
---|
142 | n/a | |
---|
143 | n/a | __coverity_tainted_data_sanitize__(y); |
---|
144 | n/a | __coverity_tainted_data_sanitize__(m); |
---|
145 | n/a | __coverity_tainted_data_sanitize__(d); |
---|
146 | n/a | __coverity_tainted_data_sanitize__(hh); |
---|
147 | n/a | __coverity_tainted_data_sanitize__(mm); |
---|
148 | n/a | __coverity_tainted_data_sanitize__(ss); |
---|
149 | n/a | __coverity_tainted_data_sanitize__(dstflag); |
---|
150 | n/a | |
---|
151 | n/a | return result; |
---|
152 | n/a | } |
---|
153 | n/a | |
---|
154 | n/a | static int |
---|
155 | n/a | ymd_to_ord(int year, int month, int day) |
---|
156 | n/a | { |
---|
157 | n/a | int ord = 0; |
---|
158 | n/a | |
---|
159 | n/a | __coverity_tainted_data_sanitize__(year); |
---|
160 | n/a | __coverity_tainted_data_sanitize__(month); |
---|
161 | n/a | __coverity_tainted_data_sanitize__(day); |
---|
162 | n/a | |
---|
163 | n/a | return ord; |
---|
164 | n/a | } |
---|
165 | n/a | |
---|
166 | n/a | static int |
---|
167 | n/a | normalize_date(int *year, int *month, int *day) |
---|
168 | n/a | { |
---|
169 | n/a | __coverity_tainted_data_sanitize__(*year); |
---|
170 | n/a | __coverity_tainted_data_sanitize__(*month); |
---|
171 | n/a | __coverity_tainted_data_sanitize__(*day); |
---|
172 | n/a | |
---|
173 | n/a | return 0; |
---|
174 | n/a | } |
---|
175 | n/a | |
---|
176 | n/a | static int |
---|
177 | n/a | weekday(int year, int month, int day) |
---|
178 | n/a | { |
---|
179 | n/a | int w = 0; |
---|
180 | n/a | |
---|
181 | n/a | __coverity_tainted_data_sanitize__(year); |
---|
182 | n/a | __coverity_tainted_data_sanitize__(month); |
---|
183 | n/a | __coverity_tainted_data_sanitize__(day); |
---|
184 | n/a | |
---|
185 | n/a | return w; |
---|
186 | n/a | } |
---|
187 | n/a | |
---|