Browse code

libclamav/dlp.c: fix CC detection and chksumming (bb#1264)

git-svn: trunk@4622

Tomasz Kojm authored on 2009/01/19 23:18:34
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jan 19 15:38:39 CET 2009 (tk)
2
+---------------------------------
3
+ * libclamav/dlp.c: fix CC detection and chksumming (bb#1264)
4
+
1 5
 Fri Jan 16 15:26:50 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * libclamav/dlp.c: fix detection of single stripped SSNs (bb#1354)
... ...
@@ -117,7 +117,7 @@ static int ssn_max_group[MAX_AREA+1] = { 0,
117 117
 
118 118
 int dlp_is_valid_cc(const unsigned char *buffer, int length)
119 119
 {
120
-    int even = 1;
120
+    int mult = 0;
121 121
     int sum = 0;
122 122
     int i = 0;
123 123
     int val = 0;
... ...
@@ -138,31 +138,33 @@ int dlp_is_valid_cc(const unsigned char *buffer, int length)
138 138
 
139 139
     for(i = 0; i < length; i++)
140 140
     {
141
-        if(isdigit(buffer[i]) == 0)
141
+	if(isdigit(buffer[i]) == 0)
142 142
 	{
143
-	    if(isspace(buffer[i]))
143
+	    if(buffer[i] == ' ' || buffer[i] == '-')
144 144
 		continue;
145 145
 	    else
146 146
 		break;
147 147
 	}
148
-
149 148
 	cc_digits[digits] = buffer[i];
150 149
 	digits++;
151
-        val = buffer[i] - '0';
152
-        
153
-        if(even)
154
-        {
155
-            if((val *= 2) > 9) val = (val - 10) + 1;
156
-        }
157
-        
158
-        even = !even;
159
-        sum += val;
160 150
     }
161 151
     cc_digits[digits] = 0;
162
-    if(i < length && isdigit(buffer[i]))
152
+
153
+    if(digits < 13 || (i < length && isdigit(buffer[i])))
163 154
 	return 0;
164 155
 
165
-    if((sum % 10 != 0) || (digits < 13))
156
+    for(i = digits - 1; i >= 0; i--)
157
+    {
158
+	val = cc_digits[i] - '0';
159
+        if(mult)
160
+        {
161
+            if((val *= 2) > 9) val -= 9;
162
+        }
163
+	mult = !mult;
164
+	sum += val;
165
+    }
166
+
167
+    if(sum % 10)
166 168
 	return 0;
167 169
 
168 170
     if(digits == 13) /* VISA */