- rel_tag[0] = 0;
- href_tag[0] = 0;
-
- if ((link_tag_end) && (link_tag_end > link_tag_start)) {
- int len;
- len = link_tag_end - link_tag_start;
- if (len > sizeof work_buffer) len = sizeof work_buffer;
- memcpy(work_buffer, link_tag_start, len);
-
- char *rel_start = NULL;
- char *rel_end = NULL;
- rel_start = bmstrcasestr(work_buffer, "rel=");
- if (rel_start) {
- rel_start = strchr(rel_start, '\"');
- if (rel_start) {
- ++rel_start;
- rel_end = strchr(rel_start, '\"');
- if ((rel_end) && (rel_end > rel_start)) {
- safestrncpy(rel_tag, rel_start, rel_end - rel_start + 1);
- }
- }
- }
-
- char *href_start = NULL;
- char *href_end = NULL;
- href_start = bmstrcasestr(work_buffer, "href=");
- if (href_start) {
- href_start = strchr(href_start, '\"');
- if (href_start) {
- ++href_start;
- href_end = strchr(href_start, '\"');
- if ((href_end) && (href_end > href_start)) {
- safestrncpy(href_tag, href_start, href_end - href_start + 1);
- }
- }
- }
-
- if (!strcasecmp(rel, rel_tag)) {
- safestrncpy(target_buf, href_tag, target_size);
- return;
- }
-
+ if (link_tag_end == NULL)
+ break;
+ for (i=0; i < 1; i++ ){
+ rel_start = cbmstrcasestr(link_tag_start, "rel=");
+ if ((rel_start == NULL) ||
+ (rel_start > link_tag_end))
+ continue;
+
+ rel_start = strchr(rel_start, '\"');
+ if ((rel_start == NULL) ||
+ (rel_start > link_tag_end))
+ continue;
+ ++rel_start;
+ rel_end = strchr(rel_start, '\"');
+ if ((rel_end == NULL) ||
+ (rel_end == rel_start) ||
+ (rel_end >= link_tag_end) )
+ continue;
+ if (strncasecmp(rel, rel_start, repllen)!= 0)
+ continue; /* didn't match? never mind... */
+
+ href_start = cbmstrcasestr(link_tag_start, "href=");
+ if ((href_start == NULL) ||
+ (href_start >= link_tag_end))
+ continue;
+ href_start = strchr(href_start, '\"');
+ if ((href_start == NULL) |
+ (href_start >= link_tag_end))
+ continue;
+ ++href_start;
+ href_end = strchr(href_start, '\"');
+ if ((href_end == NULL) ||
+ (href_end == href_start) ||
+ (href_start >= link_tag_end))
+ continue;
+ StrBufPlain(target_buf, href_start, href_end - href_start);