1 /*
2 Coverity model file in order to avoid false-positive
3 */
4 
5 #define NULL (void *)0
6 
7 typedef unsigned char   jsbytecode;
8 typedef unsigned short  uint16_t;
9 typedef unsigned int    uint32_t;
10 typedef unsigned int    int32_t;
11 typedef unsigned char   uint8_t;
12 
13 static const uint16_t CHUNK_HEAD_SIZE = 8;
14 
assert(bool expr)15 void assert(bool expr) {
16   if (!expr) {
17     __coverity_panic__();
18   }
19 }
20 
21 #define ERREXIT(cinfo, err) __coverity_panic__();
22 
MOZ_ASSUME_UNREACHABLE(char * str)23 void  MOZ_ASSUME_UNREACHABLE(char * str) {
24   __coverity_panic__();
25 }
26 
MOZ_ReportAssertionFailure(const char * aStr,const char * aFilename,int aLine)27 static void MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
28     int aLine) {
29   __coverity_panic__();
30 }
31 
MOZ_ReportCrash(const char * aStr,const char * aFilename,int aLine)32 static void MOZ_ReportCrash(const char* aStr, const char* aFilename,
33     int aLine) {
34   __coverity_panic__();
35 }
36 
37 #define MOZ_ASSERT(expr, msg) assert(!!(expr))
38 
39 #define MOZ_ASSERT(expr) assert(!!(expr))
40 
41 #define NS_ASSERTION(expr, msg) assert(!!(expr))
42 
43 #define PORT_Assert(expr) assert(!!(expr))
44 
45 #define PR_ASSERT(expr) assert(!!(expr))
46 
GET_JUMP_OFFSET(jsbytecode * pc)47 int GET_JUMP_OFFSET(jsbytecode* pc) {
48   __coverity_tainted_data_sanitize__(&pc[1]);
49   __coverity_tainted_data_sanitize__(&pc[2]);
50   __coverity_tainted_data_sanitize__(&pc[3]);
51   __coverity_tainted_data_sanitize__(&pc[4]);
52 
53   return 0;
54 }
55 
56 
57 // Data sanity checkers
58 #define XPT_SWAB16(data) __coverity_tainted_data_sanitize__(&data)
59 
60 #define XPT_SWAB32(data) __coverity_tainted_data_sanitize__(&data)
61 
62 
GET_UINT24(const jsbytecode * pc)63 static unsigned GET_UINT24(const jsbytecode* pc) {
64   __coverity_tainted_data_sanitize__(static_cast<void*>(pc));
65   //return unsigned((pc[1] << 16) | (pc[2] << 8) | pc[3]);
66   return 0;
67 }
68 
69 
70 class HeaderParser {
71 
72 private:
73   class ChunkHeader {
74 
75     uint8_t mRaw[CHUNK_HEAD_SIZE];
76 
ChunkSize() const77     HeaderParser::ChunkHeader::ChunkSize() const {
78       __coverity_tainted_data_sanitize__(static_cast<void*>(&mRaw[4]));
79       __coverity_tainted_data_sanitize__(static_cast<void*>(&mRaw[5]));
80       __coverity_tainted_data_sanitize__(static_cast<void*>(&mRaw[6]));
81       __coverity_tainted_data_sanitize__(static_cast<void*>(&mRaw[7]));
82 
83       return ((mRaw[7] << 24) | (mRaw[6] << 16) | (mRaw[5] << 8) | (mRaw[4]));
84     }
85   };
86 };
87 
NS_DebugBreak(uint32_t aSeverity,const char * aStr,const char * aExpr,const char * aFile,int32_t aLine)88 void NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
89     const char* aFile, int32_t aLine) {
90   __coverity_panic__();
91 }
92 
Swap(uint32_t * value)93 static inline void Swap(uint32_t* value) {
94   __coverity_tainted_data_sanitize__(static_cast<void*>(&value));
95   *value =  (*value >> 24) |
96            ((*value >> 8)  & 0x0000ff00) |
97            ((*value << 8)  & 0x00ff0000) |
98             (*value << 24);
99 }
100 
xtolong(const uint8_t * ll)101 static uint32_t xtolong (const uint8_t *ll) {
102   __coverity_tainted_data_sanitize__(static_cast<void*>(&ll[0]));
103   __coverity_tainted_data_sanitize__(static_cast<void*>(&ll[1]));
104   __coverity_tainted_data_sanitize__(static_cast<void*>(&ll[2]));
105   __coverity_tainted_data_sanitize__(static_cast<void*>(&ll[3]));
106 
107   return (uint32_t)( (ll [0] <<  0) |
108                      (ll [1] <<  8) |
109                      (ll [2] << 16) |
110                      (ll [3] << 24) );
111 }
112 
113 class ByteReader {
114 public:
115   const uint8_t* Read(size_t aCount);
ReadU24()116   uint32_t ReadU24() {
117     const uint8_t *ptr = Read(3);
118     if (!ptr) {
119       MOZ_ASSERT(false);
120       return 0;
121     }
122     __coverity_tainted_data_sanitize__(static_cast<void*>(&ptr[0]));
123     __coverity_tainted_data_sanitize__(static_cast<void*>(&ptr[1]));
124     __coverity_tainted_data_sanitize__(static_cast<void*>(&ptr[2]));
125     return ptr[0] << 16 | ptr[1] << 8 | ptr[2];
126   }
127 };
128 
129