Ticket #38: verifycancel-newsgroups.patch
File verifycancel-newsgroups.patch, 2.4 KB (added by , 14 years ago) |
---|
-
art.c
old new 1137 1137 } 1138 1138 1139 1139 /* 1140 ** Verify if a cancel message is valid. If the user posting the cancel 1141 ** matches the user who posted the article, return the list of filenames 1142 ** otherwise return NULL. 1140 ** Verify if a cancel message is valid. Unless at least one group in the 1141 ** cancel message's Newsgroups: line can be found in the Newsgroups: line 1142 ** of the article to be cancelled, the cancel is considered bogus and 1143 ** false is returned. 1143 1144 */ 1144 1145 static bool 1145 1146 ARTcancelverify(const ARTDATA *data, const char *MessageID, TOKEN *token) 1146 1147 { 1147 1148 const char *p; 1148 1149 char *q, *q1; 1150 char **gp; 1149 1151 const char *local; 1150 1152 char buff[SMBUF]; 1151 1153 ARTHANDLE *art; … … 1155 1157 return false; 1156 1158 if ((art = SMretrieve(*token, RETR_HEAD)) == NULL) 1157 1159 return false; 1158 local = wire_findheader(art->data, art->len, "Sender"); 1160 /* Copy Newsgroups: from article be to cancelled to q. 1161 * Double-terminate q (sentinel) */ 1162 local = wire_findheader(art->data, art->len, "Newsgroups"); 1159 1163 if (local == NULL) { 1160 local = wire_findheader(art->data, art->len, "From"); 1161 if (local == NULL) { 1162 SMfreearticle(art); 1163 return false; 1164 } 1164 SMfreearticle(art); 1165 return false; 1165 1166 } 1166 1167 for (p = local; p < art->data + art->len; p++) { 1167 1168 if (*p == '\r' || *p == '\n') … … 1171 1172 SMfreearticle(art); 1172 1173 return false; 1173 1174 } 1174 q = xmalloc(p - local + 1);1175 q = xmalloc(p - local + 2); 1175 1176 memcpy(q, local, p - local); 1176 1177 SMfreearticle(art); 1177 1178 q[p - local] = '\0'; 1178 HeaderCleanFrom(q);1179 q[p - local + 1] = '\0'; 1179 1180 1180 /* Compare canonical forms. */ 1181 q1 = xstrdup(data->Poster); 1182 HeaderCleanFrom(q1); 1183 if (strcmp(q, q1) != 0) { 1184 r = false; 1185 sprintf(buff, "\"%.50s\" wants to cancel %s by \"%.50s\"", 1186 q1, MaxLength(MessageID, MessageID), q); 1187 ARTlog(data, ART_REJECT, buff); 1188 } 1189 else { 1190 r = true; 1181 /* replace separator , by \0 */ 1182 for (q1 = q; *q1; q1++) 1183 if (NG_ISSEP(*q1)) 1184 *q1 = '\0'; 1185 1186 r = false; 1187 for (gp = data->Newsgroups.List; *gp && !r; gp++) { 1188 for (q1 = q; *q1; q1 += strlen(q1) + 1) { 1189 if (strcmp(q1, *gp) == 0) { 1190 r = true; 1191 break; 1192 } 1193 } 1191 1194 } 1192 free(q1);1193 1195 free(q); 1196 1197 if (!r) { 1198 sprintf(buff, "no matching Newsgroups in cancel %s", 1199 MaxLength(MessageID, MessageID)); 1200 ARTlog(data, ART_REJECT, buff); 1201 } 1194 1202 return r; 1195 1203 }