Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 55 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
43 magnus 1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 02_fix_warnings.dpatch by Russell Coker <russell@coker.com.au>
3
##
4
## DP: Get rid of warnings through the use of const and more correct types
5
 
6
@DPATCH@
7
 
55 magnus 8
--- a/src/dkim.cpp
9
+++ b/src/dkim.cpp
10
@@ -172,7 +172,7 @@ int DKIM_CALL DKIMVerifyInit( DKIMContex
43 magnus 11
 }
12
 
13
 
14
-int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, char* szBuffer, int nBufLength )
15
+int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, const char* const szBuffer, int nBufLength )
16
 {
17
        CDKIMVerify* pVerify = (CDKIMVerify*)ValidateContext( pVerifyContext, false );
18
 
55 magnus 19
@@ -226,13 +226,13 @@ void DKIM_CALL DKIMVerifyFree( DKIMConte
43 magnus 20
 }
21
 
22
 
23
-char* DKIM_CALL DKIMVersion()
24
+const char* DKIM_CALL DKIMVersion()
25
 {
26
        return VERSION_STRING;
27
 }
28
 
29
 
30
-static char* DKIMErrorStrings[-1-DKIM_MAX_ERROR] = {
31
+static const char* DKIMErrorStrings[-1-DKIM_MAX_ERROR] = {
32
        "DKIM_FAIL",
33
        "DKIM_BAD_SYNTAX",
34
        "DKIM_SIGNATURE_BAD",
55 magnus 35
@@ -259,7 +259,7 @@ static char* DKIMErrorStrings[-1-DKIM_MA
43 magnus 36
 };
37
 
38
 
39
-char* DKIM_CALL DKIMGetErrorString( int ErrorCode )
40
+const char* DKIM_CALL DKIMGetErrorString( int ErrorCode )
41
 {
42
        if (ErrorCode >= 0 || ErrorCode <= DKIM_MAX_ERROR)
43
                return "Unknown";
55 magnus 44
--- a/src/dkim.h
45
+++ b/src/dkim.h
46
@@ -154,14 +154,14 @@ int DKIM_CALL DKIMSignGetSig2( DKIMConte
43 magnus 47
 void DKIM_CALL DKIMSignFree( DKIMContext* pSignContext );
48
 
49
 int DKIM_CALL DKIMVerifyInit( DKIMContext* pVerifyContext, DKIMVerifyOptions* pOptions );
50
-int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, char* szBuffer, int nBufLength );
51
+int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, const char* szBuffer, int nBufLength );
52
 int DKIM_CALL DKIMVerifyResults( DKIMContext* pVerifyContext );
53
 int DKIM_CALL DKIMVerifyGetDetails( DKIMContext* pVerifyContext, int* nSigCount, DKIMVerifyDetails** pDetails, char* szPractices );
54
 void DKIM_CALL DKIMVerifyFree( DKIMContext* pVerifyContext );
55
 
56
-char *DKIM_CALL DKIMVersion();
57
+const char *DKIM_CALL DKIMVersion();
58
 
59
-char *DKIM_CALL DKIMGetErrorString( int ErrorCode );
60
+const char *DKIM_CALL DKIMGetErrorString( int ErrorCode );
61
 
62
 #ifdef __cplusplus
63
 }
55 magnus 64
--- a/src/dkimbase.cpp
65
+++ b/src/dkimbase.cpp
66
@@ -118,10 +118,10 @@ void CDKIMBase::Free( char* szBuffer )
43 magnus 67
 // Process - split buffers into lines without any CRs or LFs at the end.
68
 //
69
 ////////////////////////////////////////////////////////////////////////////////
70
-int CDKIMBase::Process( char* szBuffer, int nBufLength, bool bEOF )
71
+int CDKIMBase::Process( const char* szBuffer, int nBufLength, bool bEOF )
72
 {
73
-       char* p = szBuffer;
74
-       char* e = szBuffer + nBufLength;
75
+       const char* p = szBuffer;
76
+       const char* e = szBuffer + nBufLength;
77
 
78
        while( p < e )
79
        {
55 magnus 80
@@ -208,7 +208,8 @@ int CDKIMBase::ProcessFinal(void)
43 magnus 81
        {
82
                m_InHeaders = false;
83
                ProcessHeaders();
84
-               ProcessBody("", 0, true);
85
+               /* type conversion should be safe as length is zero */
86
+               ProcessBody((char *)"", 0, true);
87
        }
88
 
89
        return DKIM_SUCCESS;
55 magnus 90
@@ -338,9 +339,9 @@ string CDKIMBase::RelaxHeader( const str
43 magnus 91
 
92
        CompressSWSP(sTemp);
93
 
94
-       unsigned cpos = sTemp.find(':');
95
+       string::size_type cpos = sTemp.find(':');
96
 
97
-       if (cpos == -1)
98
+       if (cpos == string::npos)
99
        {
100
                // no colon?!
101
        }
55 magnus 102
--- a/src/dkimbase.h
103
+++ b/src/dkimbase.h
104
@@ -41,7 +41,7 @@ public:
43 magnus 105
 
106
        int Init(void);
107
 
108
-       int Process( char* szBuffer, int nBufLength, bool bEOF );
109
+       int Process( const char* szBuffer, int nBufLength, bool bEOF );
110
        int ProcessFinal(void);
111
 
112
        int Alloc( char*& szBuffer, int nRequiredSize );
55 magnus 113
--- a/src/dkimsign.cpp
114
+++ b/src/dkimsign.cpp
115
@@ -144,7 +144,7 @@ void CDKIMSign::Hash( const char* szBuff
43 magnus 116
 
117
        fwrite( szBuffer, 1, nBufLength, fpdebug );
118
 
119
-       /** END DEBUG CODE **/
120
+       ** END DEBUG CODE **/
121
 
122
        if( bAllmanOnly )
123
        {
55 magnus 124
@@ -555,7 +555,7 @@ void CDKIMSign::InitSig(void)
43 magnus 125
 //               if bFold, fold at cbrk char
126
 //
127
 ////////////////////////////////////////////////////////////////////////////////
128
-void CDKIMSign::AddTagToSig( char* Tag, const string &sValue, char cbrk, bool bFold )
129
+void CDKIMSign::AddTagToSig( const char* const Tag, const string &sValue, char cbrk, bool bFold )
130
 {
131
        int nTagLen = strlen(Tag);
132
 
55 magnus 133
@@ -583,10 +583,10 @@ void CDKIMSign::AddTagToSig( char* Tag,
43 magnus 134
 // AddTagToSig - add tag and numeric value to signature folding if necessary
135
 //
136
 ////////////////////////////////////////////////////////////////////////////////
137
-void CDKIMSign::AddTagToSig( char* Tag, unsigned long nValue )
138
+void CDKIMSign::AddTagToSig( const char* const Tag, unsigned long nValue )
139
 {
140
        char szValue[64];
141
-       sprintf( szValue, "%u", nValue );
142
+       sprintf( szValue, "%lu", nValue );
143
        AddTagToSig( Tag, szValue, 0, false );
144
 }
145
 
55 magnus 146
@@ -686,7 +686,7 @@ void CDKIMSign::AddFoldedValueToSig( con
43 magnus 147
 // GetSig - compute hash and return signature header in szSignature
148
 //
149
 ////////////////////////////////////////////////////////////////////////////////
150
-int CDKIMSign::GetSig( char* szPrivKey, char* szSignature, int nSigLength )
151
+int CDKIMSign::GetSig( char* szPrivKey, char* szSignature, unsigned nSigLength )
152
 {
153
        if( szPrivKey == NULL )
154
        {
55 magnus 155
@@ -794,7 +794,6 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 156
        int size;
157
        int len;
158
        char* buf;
159
-       int pos = 0;
160
 
161
        // construct the DKIM-Signature: header and add to hash
162
        InitSig();
55 magnus 163
@@ -879,7 +878,7 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 164
                }
165
                BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
166
                BIO_push(b64, bio);
167
-               if (BIO_write(b64, Hash, nHashLen) < nHashLen) 
168
+               if (BIO_write(b64, Hash, nHashLen) < (int)nHashLen) 
169
                {
170
                  BIO_free_all(b64);
171
                  return DKIM_OUT_OF_MEMORY;
55 magnus 172
@@ -993,7 +992,7 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 173
     }
174
     BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
175
     BIO_push(b64, bio);
176
-    if (BIO_write(b64, sig, siglen) < siglen) 
177
+    if (BIO_write(b64, sig, siglen) < (int)siglen) 
178
        {
179
       OPENSSL_free(sig);
180
       BIO_free_all(b64);
55 magnus 181
--- a/src/dkimsign.h
182
+++ b/src/dkimsign.h
183
@@ -32,7 +32,7 @@ public:
43 magnus 184
 
185
        int Init( DKIMSignOptions* pOptions );
186
 
187
-       int GetSig( char* szPrivKey, char* szSignature, int nSigLength );
188
+       int GetSig( char* szPrivKey, char* szSignature, unsigned nSigLength );
189
        int GetSig2( char* szPrivKey, char** pszSignature );
190
 
191
        virtual int ProcessHeaders(void);
55 magnus 192
@@ -50,8 +50,8 @@ protected:
43 magnus 193
        bool ParseFromAddress( void );
194
 
195
        void InitSig(void);
196
-       void AddTagToSig( char* Tag, const string &sValue, char cbrk, bool bFold );
197
-       void AddTagToSig( char* Tag, unsigned long nValue );
198
+       void AddTagToSig( const char* const Tag, const string &sValue, char cbrk, bool bFold );
199
+       void AddTagToSig( const char* const Tag, unsigned long nValue );
200
        void AddInterTagSpace( int nSizeOfNextTag );
201
        void AddFoldedValueToSig( const string &sValue, char cbrk );
202
 
55 magnus 203
--- a/src/dkimverify.cpp
204
+++ b/src/dkimverify.cpp
56 magnus 205
@@ -210,7 +210,7 @@ void DecodeQuotedPrintable(char *ptr)
206
 ////////////////////////////////////////////////////////////////////////////////
207
 unsigned DecodeBase64(char *ptr)
208
 {
209
-       static const unsigned char base64_table[256] = {
210
+       static const signed char base64_table[256] = {
211
                -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
212
                -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
213
                -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
214
@@ -227,10 +227,10 @@ unsigned DecodeBase64(char *ptr)
215
 
216
        while (*s != '\0')
217
        {
218
-               unsigned char value = base64_table[*s++];
219
-               if ( (signed char)value >= 0 )
220
+               signed char value = base64_table[*s++];
221
+               if ( value >= 0 )
222
                {
223
-                       b64accum = (b64accum << 6) | value;
224
+                   b64accum = (b64accum << 6) | (unsigned char)value;
225
                        b64shift += 6;
226
                        if (b64shift >= 8)
227
                        {
55 magnus 228
@@ -442,7 +442,7 @@ int CDKIMVerify::GetResults(void)
43 magnus 229
 {
230
        ProcessFinal();
231
 
232
-       int SuccessCount=0;
233
+       unsigned int SuccessCount=0;
234
        int TestingFailures=0;
235
        int RealFailures=0;
236
 
55 magnus 237
@@ -643,7 +643,7 @@ void SignatureInfo::Hash( const char* sz
43 magnus 238
        /** END DEBUG CODE **/
239
 #endif
240
 
241
-       if (IsBody && BodyLength != -1)
242
+       if (IsBody && BodyLength != (unsigned)-1)
243
        {
244
                VerifiedBodyCount += nBufLength;
245
                if (VerifiedBodyCount > BodyLength)
55 magnus 246
@@ -1050,7 +1050,7 @@ int CDKIMVerify::ParseDKIMSignature( con
43 magnus 247
        // body count
248
        if (values[8] == NULL || !m_HonorBodyLengthTag)
249
        {
250
-               sig.BodyLength = -1;
251
+               sig.BodyLength = (unsigned)-1;
252
        }
253
        else
254
        {
55 magnus 255
@@ -1088,17 +1088,17 @@ int CDKIMVerify::ParseDKIMSignature( con
43 magnus 256
        // expiration time
257
        if (values[11] == NULL)
258
        {
259
-               sig.ExpireTime = -1;
260
+               sig.ExpireTime = (unsigned)-1;
261
        }
262
        else
263
        {
264
                if (!ParseUnsigned(values[11], &sig.ExpireTime))
265
                        return DKIM_BAD_SYNTAX;
266
 
267
-               if (sig.ExpireTime != -1)
268
+               if (sig.ExpireTime != (unsigned)-1)
269
                {
270
                        // the value of x= MUST be greater than the value of t= if both are present
271
-                       if (SignedTime != -1 && sig.ExpireTime <= SignedTime)
272
+                       if (SignedTime != (unsigned)-1 && sig.ExpireTime <= SignedTime)
273
                                return DKIM_BAD_SYNTAX;
274
 
275
                        // todo: if possible, use the received date/time instead of the current time
55 magnus 276
@@ -1200,7 +1200,7 @@ int CDKIMVerify::ProcessBody( char* szBu
43 magnus 277
 }
278
 
279
 
280
-SelectorInfo::SelectorInfo(const string &sSelector, const string &sDomain) : Selector(sSelector), Domain(sDomain)
281
+SelectorInfo::SelectorInfo(const string &sSelector, const string &sDomain) : Domain(sDomain), Selector(sSelector)
282
 {
283
        AllowSHA1 = true;
284
        AllowSHA256 = true;
55 magnus 285
@@ -1241,7 +1241,7 @@ int SelectorInfo::Parse( char* Buffer )
43 magnus 286
                        return DKIM_SELECTOR_INVALID;           // todo: maybe create a new error code for unsupported selector version
287
 
288
                // make sure v= is the first tag in the response        // todo: maybe don't enforce this, it seems unnecessary
289
-               for (int j=1; j<sizeof(values)/sizeof(values[0]); j++)
290
+               for (unsigned j=1; j<sizeof(values)/sizeof(values[0]); j++)
291
                {
292
                        if (values[j] != NULL && values[j] < values[0])
293
                        {
55 magnus 294
--- a/src/libdkimtest.cpp
295
+++ b/src/libdkimtest.cpp
296
@@ -60,9 +60,9 @@ int DKIM_CALL SelectorCallback(const cha
43 magnus 297
 int main(int argc, char* argv[])
298
 {
299
        int n;
300
-       char* PrivKeyFile = "test.pem";
301
-       char* MsgFile = "test.msg";
302
-       char* OutFile = "signed.msg";
303
+       const char* PrivKeyFile = "test.pem";
304
+       const char* MsgFile = "test.msg";
305
+       const char* OutFile = "signed.msg";
306
        int nPrivKeyLen;
307
        char PrivKey[2048];
308
        char Buffer[1024];