comparison libpurple/protocols/msn/notification.c @ 24127:c5488f91bf3b

Fix a possible xmlnode leak and an extra g_strdup when processing incoming MSN pages.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 27 Sep 2008 03:20:48 +0000
parents 384217df4ee7
children 345ed41d807b
comparison
equal deleted inserted replaced
24125:c3dbdb98a119 24127:c5488f91bf3b
1058 static void 1058 static void
1059 ipg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len) 1059 ipg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
1060 { 1060 {
1061 PurpleConnection *gc; 1061 PurpleConnection *gc;
1062 MsnUserList *userlist; 1062 MsnUserList *userlist;
1063 char *who = NULL, *text = NULL; 1063 const char *who = NULL;
1064 char *text = NULL;
1064 const char *id = NULL; 1065 const char *id = NULL;
1065 xmlnode *payloadNode, *from, *msg, *textNode; 1066 xmlnode *payloadNode, *from, *msg, *textNode;
1066 1067
1067 purple_debug_misc("msn", "Incoming Page: {%s}\n", payload); 1068 purple_debug_misc("msn", "Incoming Page: {%s}\n", payload);
1068 1069
1102 </BODY> 1103 </BODY>
1103 </MSG> 1104 </MSG>
1104 </NOTIFICATION> 1105 </NOTIFICATION>
1105 */ 1106 */
1106 1107
1107 if (!(payloadNode = xmlnode_from_str(payload, len)) || 1108 payloadNode = xmlnode_from_str(payload, len);
1108 !(from = xmlnode_get_child(payloadNode, "FROM")) || 1109 if (!payloadNode)
1110 return;
1111
1112 if (!(from = xmlnode_get_child(payloadNode, "FROM")) ||
1109 !(msg = xmlnode_get_child(payloadNode, "MSG")) || 1113 !(msg = xmlnode_get_child(payloadNode, "MSG")) ||
1110 !(textNode = xmlnode_get_child(msg, "BODY/TEXT"))) 1114 !(textNode = xmlnode_get_child(msg, "BODY/TEXT"))) {
1111 return; 1115 xmlnode_free(payloadNode);
1112 1116 return;
1113 who = g_strdup(xmlnode_get_attrib(from, "name")); 1117 }
1118
1119 who = xmlnode_get_attrib(from, "name");
1114 if (!who) return; 1120 if (!who) return;
1115 1121
1116 text = xmlnode_get_data(textNode); 1122 text = xmlnode_get_data(textNode);
1117 1123
1118 /* Match number to user's mobile number, FROM is a phone number if the 1124 /* Match number to user's mobile number, FROM is a phone number if the
1119 other side page you using your phone number */ 1125 other side page you using your phone number */
1120 if (!strncmp(who, "tel:+", 5)) { 1126 if (!strncmp(who, "tel:+", 5)) {
1121 MsnUser *user = 1127 MsnUser *user =
1122 msn_userlist_find_user_with_mobile_phone(userlist, who + 4); 1128 msn_userlist_find_user_with_mobile_phone(userlist, who + 4);
1123 1129
1124 if(user && user->passport) { 1130 if (user && user->passport)
1125 g_free(who); 1131 who = user->passport;
1126 who = g_strdup(user->passport);
1127 }
1128 } 1132 }
1129 1133
1130 id = xmlnode_get_attrib(msg, "id"); 1134 id = xmlnode_get_attrib(msg, "id");
1131 1135
1132 if (id && !strcmp(id, "407")) { 1136 if (id && !strcmp(id, "407")) {
1141 } else { 1145 } else {
1142 serv_got_im(gc, who, text, 0, time(NULL)); 1146 serv_got_im(gc, who, text, 0, time(NULL));
1143 } 1147 }
1144 1148
1145 g_free(text); 1149 g_free(text);
1146 g_free(who);
1147 xmlnode_free(payloadNode); 1150 xmlnode_free(payloadNode);
1148 } 1151 }
1149 1152
1150 static void 1153 static void
1151 ipg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 1154 ipg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)