ยปCore Development>Code coverage>Misc/coverity_model.c

Python code coverage for Misc/coverity_model.c

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