# HG changeset patch # User Luke Schierer # Date 1070236185 0 # Node ID 66d9440db6ec3aa7838c912e69bff6b99500da52 # Parent 3d49c33db741596442c798dc0c48119bbe65c89a [gaim-migrate @ 8319] marv writes: "This fixes some crashes on unusual long profile fields for yahoo, and probably msn. One test case is the yahoo [l]user "kent_nwo4life", which crashes without this patch." committer: Tailor Script diff -r 3d49c33db741 -r 66d9440db6ec src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Sun Nov 30 20:33:38 2003 +0000 +++ b/src/protocols/msn/msn.c Sun Nov 30 23:49:45 2003 +0000 @@ -1273,6 +1273,8 @@ gboolean found; gboolean has_info = FALSE; char *url_buffer; + GString *s; + int stripped_len; gaim_debug_info("msn", "In msn_got_info\n"); @@ -1332,36 +1334,38 @@ /* Nuke the html, it's easier than trying to parse the horrid stuff */ stripped = gaim_markup_strip_html(url_buffer); + stripped_len = strlen(stripped); gaim_debug_misc("msn", "stripped = %p\n", stripped); gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer); /* Gonna re-use the memory we've already got for url_buffer */ - strcpy(url_buffer, "\n"); + /* No we're not. */ + s = g_string_sized_new(strlen(url_buffer)); /* Extract their Name and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tName", 0, "\t", '\n', "Undisclosed", _("Name"), 0, NULL); if (found) has_info = TRUE; /* Extract their Age and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "\tAge", + found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tAge", 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL); if (found) has_info = TRUE; /* Extract their Gender and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "\tGender", + found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tGender", 6, "\t", '\n', "Undisclosed", _("Gender"), 0, NULL); if (found) has_info = TRUE; /* Extract their MaritalStatus and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tMaritalStatus", 0, "\t", '\n', "Undisclosed", _("Marital Status"), 0, NULL); @@ -1369,7 +1373,7 @@ has_info = TRUE; /* Extract their Location and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"), 0, NULL); @@ -1377,7 +1381,7 @@ has_info = TRUE; /* Extract their Occupation and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\t Occupation", 6, "\t", '\n', "Undisclosed", _("Occupation"), 0, NULL); @@ -1393,34 +1397,34 @@ */ /* Check if they have A Little About Me */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tA Little About Me", 1, "Favorite Things", '\n', NULL, _("A Little About Me"), 0, NULL); if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tA Little About Me", 1, "Hobbies and Interests", '\n', NULL, _("A Little About Me"), 0, NULL); } if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tA Little About Me", 1, "Favorite Quote", '\n', NULL, _("A Little About Me"), 0, NULL); } if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tA Little About Me", 1, "My Homepage\tTake a look", '\n', NULL, _("A Little About Me"), 0, NULL); } if (!found) { - gaim_markup_extract_info_field(stripped, url_buffer, + gaim_markup_extract_info_field(stripped, stripped_len, s, "\tA Little About Me", 1, "last updated", '\n', NULL, _("A Little About Me"), 0, NULL); } @@ -1429,27 +1433,27 @@ has_info = TRUE; /* Check if they have Favorite Things */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, _("Favorite Things"), 0, NULL); if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Things", 1, "Favorite Quote", '\n', NULL, "Favorite Things", 0, NULL); } if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Things", 1, "My Homepage\tTake a look", '\n', NULL, _("Favorite Things"), 0, NULL); } if (!found) { - gaim_markup_extract_info_field(stripped, url_buffer, + gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Things", 1, "last updated", '\n', NULL, _("Favorite Things"), 0, NULL); } @@ -1458,20 +1462,20 @@ has_info = TRUE; /* Check if they have Hobbies and Interests */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies and Interests", 1, "Favorite Quote", '\n', NULL, _("Hobbies and Interests"), 0, NULL); if (!found) { - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies and Interests", 1, "My Homepage\tTake a look", '\n', NULL, _("Hobbies and Interests"), 0, NULL); } if (!found) { - gaim_markup_extract_info_field(stripped, url_buffer, + gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies and Interests", 1, "last updated", '\n', NULL, _("Hobbies and Interests"), 0, NULL); } @@ -1480,13 +1484,13 @@ has_info = TRUE; /* Check if they have Favorite Quote */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote", 1, "My Homepage\tTake a look", '\n', NULL, _("Favorite Quote"), 0, NULL); if (!found) { - gaim_markup_extract_info_field(stripped, url_buffer, + gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote", 1, "last updated", '\n', NULL, _("Favorite Quote"), 0, NULL); } @@ -1495,7 +1499,7 @@ has_info = TRUE; /* Extract the last updated date and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, + found = gaim_markup_extract_info_field(stripped, stripped_len, s, "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), 0, NULL); @@ -1509,7 +1513,7 @@ "%s:
%s
\n", _("Homepage"), user_url, user_url); - strcat(url_buffer, buf); + g_string_append(s, buf); g_free(user_url); @@ -1517,12 +1521,12 @@ } /* Finish it off, and show it to them */ - strcat(url_buffer, "\n"); + g_string_append(s, "\n"); if (has_info) { gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), - NULL, url_buffer, NULL, NULL); + NULL, s->str, NULL, NULL); } else { @@ -1536,7 +1540,7 @@ g_free(stripped); g_free(url_buffer); - + g_string_free(s, TRUE); g_free(info_data->name); g_free(info_data); } diff -r 3d49c33db741 -r 66d9440db6ec src/protocols/yahoo/yahoo.c --- a/src/protocols/yahoo/yahoo.c Sun Nov 30 20:33:38 2003 +0000 +++ b/src/protocols/yahoo/yahoo.c Sun Nov 30 23:49:45 2003 +0000 @@ -2599,9 +2599,10 @@ YahooGetInfoData *info_data = (YahooGetInfoData *)data; char *stripped, *p; char buf[1024]; - gboolean found; - gboolean has_info = FALSE; + gboolean found = FALSE; char *url_buffer; + GString *s; + int stripped_len; gaim_debug_info("yahoo", "In yahoo_got_info\n"); @@ -2640,7 +2641,7 @@ /* at the moment we don't support profile pages with languages other than * english. the problem is, that every user may choose his/her own profile * language. this language has nothing to do with the preferences of the - * user which looks at the profile + * user which looks at the profile */ p = strstr(url_text, "Last Updated:"); if (!p) { @@ -2683,66 +2684,54 @@ /* nuke the html, it's easier than trying to parse the horrid stuff */ stripped = gaim_markup_strip_html(url_buffer); + stripped_len = strlen(stripped); gaim_debug_misc("yahoo", "stripped = %p\n", stripped); gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer); /* gonna re-use the memory we've already got for url_buffer */ - strcpy(url_buffer, "\n"); + /* no we're not */ + s = g_string_sized_new(strlen(url_buffer)); + g_string_append(s, "\n"); /* extract their Yahoo! ID and put it in. Don't bother marking has_info as * true, since the Yahoo! ID will always be there */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0, - NULL, _("Yahoo! ID"), 0, NULL); + if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Yahoo! ID:", 2, "\n", 0, + NULL, _("Yahoo! ID"), 0, NULL)) + g_string_append_printf(s, "%s: %s
", _("Yahoo! ID"), info_data->name); /* extract their Email address and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0, + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "My Email", 5, "\n", 0, "Private", _("Email"), 0, NULL); - if(found) - has_info = TRUE; /* extract the Nickname if it exists */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Nickname:", 1, "\n", '\n', NULL, _("Nickname"), 0, NULL); - if(found) - has_info = TRUE; /* extract their RealName and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "RealName:", 1, "\n", '\n', NULL, _("Realname"), 0, NULL); - if(found) - has_info = TRUE; /* extract their Location and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Location:", 2, "\n", '\n', NULL, _("Location"), 0, NULL); - if(found) - has_info = TRUE; /* extract their Age and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Age:", 3, "\n", '\n', NULL, _("Age"), 0, NULL); - if(found) - has_info = TRUE; /* extract their MaritalStatus and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "MaritalStatus:", 3, "\n", '\n', "No Answer", _("Marital Status"), 0, NULL); - if(found) - has_info = TRUE; /* extract their Gender and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Gender:", 3, "\n", '\n', "No Answer", _("Gender"), 0, NULL); - if(found) - has_info = TRUE; /* extract their Occupation and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n', + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Occupation:", 2, "\n", '\n', NULL, _("Occupation"), 0, NULL); - if(found) - has_info = TRUE; /* Hobbies, Latest News, and Favorite Quote are a bit different, since the * values can contain embedded newlines... but any or all of them can also @@ -2752,51 +2741,40 @@ * bunch. */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News", - '\n', NULL, _("Hobbies"), 0, NULL); - if(!found) + if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Latest News", + '\n', NULL, _("Hobbies"), 0, NULL)) { - found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote", - '\n', NULL, _("Hobbies"), 0, NULL); - if(!found) + if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Favorite Quote", + '\n', NULL, _("Hobbies"), 0, NULL)) { - found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links", + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Hobbies:", 1, "Links", '\n', NULL, _("Hobbies"), 0, NULL); - if(found) - has_info = TRUE; } else - has_info = TRUE; + found = TRUE; } else - has_info = TRUE; - - found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote", - '\n', NULL, _("Latest News"), 0, NULL); - if(!found) + found = TRUE; + + if (!gaim_markup_extract_info_field(stripped, stripped_len, s, "Latest News:", 1, "Favorite Quote", + '\n', NULL, _("Latest News"), 0, NULL)) { - found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links", + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Latest News:", 1, "Links", '\n', NULL, _("Latest News"), 0, NULL); - if(found) - has_info = TRUE; } else - has_info = TRUE; - - found = gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links", + found = TRUE; + + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote:", 0, "Links", '\n', NULL, _("Favorite Quote"), 0, NULL); - if(found) - has_info = TRUE; /* Home Page will either be "No home page specified", * or "Home Page: " and a link. */ p = strstr(stripped, "No home page specified"); if(!p) { - found = gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL, + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Home Page:", 1, " ", 0, NULL, _("Home Page"), 1, NULL); - if(found) - has_info = TRUE; } /* Cool Link {1,2,3} is also different. If "No cool link specified" exists, @@ -2807,52 +2785,46 @@ p = strstr(stripped,"No cool link specified"); if (!p) { - found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL, - _("Cool Link 1"), 1, NULL); - if(found) + if (gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 1:", 1, " ", 0, NULL, + _("Cool Link 1"), 1, NULL)) { - has_info = TRUE; - found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL, - _("Cool Link 2"), 1, NULL); - if(found) - gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL, + found = TRUE; + if (gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 2:", 1, " ", 0, NULL, + _("Cool Link 2"), 1, NULL)) + gaim_markup_extract_info_field(stripped, stripped_len, s, "Cool Link 3:", 1, " ", 0, NULL, _("Cool Link 3"), 1, NULL); } } /* see if Member Since is there, and if so, extract it. */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:", + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Member Since:", 1, "Last Updated:", '\n', NULL, _("Member Since"), 0, NULL); - if(found) - has_info = TRUE; /* extract the Last Updated date and put it in */ - found = gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL, + found |= gaim_markup_extract_info_field(stripped, stripped_len, s, "Last Updated:", 1, "\n", '\n', NULL, _("Last Updated"), 0, NULL); - if(found) - has_info = TRUE; /* finish off the html */ - strcat(url_buffer, "\n"); + g_string_append(s, "\n"); g_free(stripped); - if(has_info) + if(found) { /* show it to the user */ gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL, - url_buffer, NULL, NULL); + s->str, NULL, NULL); } else { - char primary[256]; - g_snprintf(primary, sizeof(primary), - _("User information for %s unavailable"), info_data->name); + char *primary; + primary = g_strdup_printf(_("User information for %s unavailable"), info_data->name); gaim_notify_error(info_data->gc, NULL, primary, - _("The user's profile is empty.")); + _("The user's profile is empty.")); + g_free(primary); } g_free(url_buffer); - + g_string_free(s, TRUE); g_free(info_data->name); g_free(info_data); } diff -r 3d49c33db741 -r 66d9440db6ec src/util.c --- a/src/util.c Sun Nov 30 20:33:38 2003 +0000 +++ b/src/util.c Sun Nov 30 23:49:45 2003 +0000 @@ -434,7 +434,7 @@ } gboolean -gaim_markup_extract_info_field(const char *str, char *dest_buffer, +gaim_markup_extract_info_field(const char *str, int len, GString *dest, const char *start_token, int skip, const char *end_token, char check_value, const char *no_value_token, @@ -442,10 +442,9 @@ const char *link_prefix) { const char *p, *q; - char buf[1024]; g_return_val_if_fail(str != NULL, FALSE); - g_return_val_if_fail(dest_buffer != NULL, FALSE); + g_return_val_if_fail(dest != NULL, FALSE); g_return_val_if_fail(start_token != NULL, FALSE); g_return_val_if_fail(end_token != NULL, FALSE); g_return_val_if_fail(display_name != NULL, FALSE); @@ -457,6 +456,9 @@ p += strlen(start_token) + skip; + if (p >= str + len) + return FALSE; + if (check_value != '\0' && *p == check_value) return FALSE; @@ -466,36 +468,32 @@ (no_value_token && strncmp(p, no_value_token, strlen(no_value_token))))) { - strcat(dest_buffer, ""); - strcat(dest_buffer, display_name); - strcat(dest_buffer, ": "); + g_string_append(dest, ""); + g_string_append(dest, display_name); + g_string_append(dest, ": "); if (is_link) { - strcat(dest_buffer, "
"); + g_string_append_len(dest, p, q - p); + g_string_append(dest, "\">"); if (link_prefix) - strcat(dest_buffer, link_prefix); + g_string_append(dest, link_prefix); - strcat(dest_buffer, buf); - strcat(dest_buffer, ""); + g_string_append_len(dest, p, q - p); + g_string_append(dest, ""); } else { - memcpy(buf, p, q - p); - buf[q - p] = '\0'; - strcat(dest_buffer, buf); + g_string_append_len(dest, p, q - p); } - strcat(dest_buffer, "
\n"); + g_string_append(dest, "
\n"); return TRUE; } diff -r 3d49c33db741 -r 66d9440db6ec src/util.h --- a/src/util.h Sun Nov 30 20:33:38 2003 +0000 +++ b/src/util.h Sun Nov 30 23:49:45 2003 +0000 @@ -174,7 +174,8 @@ * protocols/yahoo/yahoo.c for example usage. * * @param str The string to parse. - * @param dest_buffer The destination buffer to append the new + * @param len The size of str. + * @param dest The destination GString to append the new * field info to. * @param start_token The beginning token. * @param skip The number of characters to skip after the @@ -188,14 +189,12 @@ * * @return TRUE if successful, or FALSE otherwise. */ -gboolean gaim_markup_extract_info_field(const char *str, char *dest_buffer, - const char *start_token, int skip, - const char *end_token, - char check_value, - const char *no_value_token, - const char *display_name, - gboolean is_link, - const char *link_prefix); +gboolean gaim_markup_extract_info_field(const char *str, int len, GString *dest, + const char *start_token, int skip, + const char *end_token, char check_value, + const char *no_value_token, + const char *display_name, gboolean is_link, + const char *link_prefix); /** * Converts HTML markup to XHTML.