]> git.pld-linux.org Git - packages/phpBB.git/blob - phpBB-viewtopic-sec_fix.patch
- security fix for viewtopic code.
[packages/phpBB.git] / phpBB-viewtopic-sec_fix.patch
1 --- ./viewtopic.php.org Sun Dec  8 03:13:40 2002
2 +++ ./viewtopic.php     Sun Dec  8 03:24:49 2002
3 @@ -444,29 +444,25 @@
4  // Was a highlight request part of the URI? Yes, this idea was\r
5  // taken from vB but we did already have a highlighter in place\r
6  // in search itself ... it's just been extended a bit!\r
7 -//\r
8 +// Fixed !!!\r
9 +$highlight_match = $highlight = '';\r
10  if ( isset($HTTP_GET_VARS['highlight']) )\r
11  {\r
12 -       $highlight_match = array();\r
13 -\r
14         //\r
15         // Split words and phrases\r
16         //\r
17 -       $words = explode(' ', trim(urldecode($HTTP_GET_VARS['highlight'])));\r
18 +       $words = explode(' ', trim(htmlspecialchars(urldecode($HTTP_GET_VARS['highlight']))));\r
19  \r
20         for($i = 0; $i < count($words); $i++)\r
21         {\r
22                 if ( trim($words[$i]) != '' )\r
23                 {\r
24 -                       $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $words[$i]) . ')\b#is';\r
25 +                       $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', phpbb_preg_quote($words[$i], '#'));\r
26                 }\r
27         }\r
28 +       unset($words);\r
29  \r
30 -       $highlight_active = ( count($highlight_match) ) ? true : false;\r
31 -}\r
32 -else\r
33 -{\r
34 -       $highlight_active = false;\r
35 +       $highlight = urlencode($HTTP_GET_VARS['highlight']);\r
36  }\r
37  \r
38  //\r
39 @@ -591,49 +587,51 @@
40  //\r
41  // If we've got a hightlight set pass it on to pagination, \r
42  // I get annoyed when I lose my highlight after the first page.\r
43 +// FIXED!!!\r
44  //\r
45 -$pagination = ( $highlight_active ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight'], $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);\r
46 +$pagination = ( $highlight_match ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight",$total_replies, $board_config['posts_per_page'], $start) :generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL ."=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies,$board_config['posts_per_page'], $start);\r
47  \r
48  //\r
49  // Send vars to template\r
50 +// FIXED!!\r
51  //\r
52  $template->assign_vars(array(\r
53         'FORUM_ID' => $forum_id,\r
54 -    'FORUM_NAME' => $forum_name,\r
55 -    'TOPIC_ID' => $topic_id,\r
56 -    'TOPIC_TITLE' => $topic_title,\r
57 +       'FORUM_NAME' => $forum_name,\r
58 +       'TOPIC_ID' => $topic_id,\r
59 +       'TOPIC_TITLE' => $topic_title,\r
60         'PAGINATION' => $pagination,\r
61 -       'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ), ceil( $total_replies / $board_config['posts_per_page'] )), \r
62 -\r
63 +       'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ),ceil( $total_replies / $board_config['posts_per_page'] )),\r
64         'POST_IMG' => $post_img,\r
65         'REPLY_IMG' => $reply_img,\r
66  \r
67         'L_AUTHOR' => $lang['Author'],\r
68         'L_MESSAGE' => $lang['Message'],\r
69 -       'L_POSTED' => $lang['Posted'], \r
70 +       'L_POSTED' => $lang['Posted'],\r
71         'L_POST_SUBJECT' => $lang['Post_subject'],\r
72         'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],\r
73         'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],\r
74 -       'L_POST_NEW_TOPIC' => $post_alt, \r
75 -       'L_POST_REPLY_TOPIC' => $reply_alt, \r
76 +       'L_POST_NEW_TOPIC' => $post_alt,\r
77 +       'L_POST_REPLY_TOPIC' => $reply_alt,\r
78         'L_BACK_TO_TOP' => $lang['Back_to_top'],\r
79         'L_DISPLAY_POSTS' => $lang['Display_posts'],\r
80 -       'L_LOCK_TOPIC' => $lang['Lock_topic'], \r
81 -       'L_UNLOCK_TOPIC' => $lang['Unlock_topic'], \r
82 -       'L_MOVE_TOPIC' => $lang['Move_topic'], \r
83 -       'L_SPLIT_TOPIC' => $lang['Split_topic'], \r
84 -       'L_DELETE_TOPIC' => $lang['Delete_topic'], \r
85 -       'L_GOTO_PAGE' => $lang['Goto_page'], \r
86 +       'L_LOCK_TOPIC' => $lang['Lock_topic'],\r
87 +       'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],\r
88 +       'L_MOVE_TOPIC' => $lang['Move_topic'],\r
89 +       'L_SPLIT_TOPIC' => $lang['Split_topic'],\r
90 +       'L_DELETE_TOPIC' => $lang['Delete_topic'],\r
91 +       'L_GOTO_PAGE' => $lang['Goto_page'],\r
92  \r
93 -       'S_TOPIC_LINK' => POST_TOPIC_URL, \r
94 +       'S_TOPIC_LINK' => POST_TOPIC_URL,\r
95         'S_SELECT_POST_DAYS' => $select_post_days,\r
96         'S_SELECT_POST_ORDER' => $select_post_order,\r
97 -       'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"), \r
98 +       'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id ."&amp;start=$start"),\r
99         'S_AUTH_LIST' => $s_auth_can,\r
100         'S_TOPIC_ADMIN' => $topic_mod,\r
101         'S_WATCH_TOPIC' => $s_watching_topic,\r
102  \r
103 -       'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight']), \r
104 +       'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL .\r
105 +       "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight"),\r
106         'U_VIEW_FORUM' => $view_forum_url,\r
107         'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,\r
108         'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,\r
109 @@ -1052,82 +1050,15 @@
110  \r
111         //\r
112         // Highlight active words (primarily for search)\r
113 +       // FIXED!!\r
114         //\r
115 -       if ( $highlight_active )\r
116 +       if ($highlight_match)\r
117         {\r
118 -               if ( preg_match('/<.*>/', $message) )\r
119 -               {\r
120 -                       $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);\r
121 -\r
122 -                       $end_html = 0;\r
123 -                       $start_html = 1;\r
124 -                       $temp_message = '';\r
125 -                       $message = ' ' . $message . ' ';\r
126 -\r
127 -                       while( $start_html = strpos($message, '<', $start_html) )\r
128 -                       {\r
129 -                               $grab_length = $start_html - $end_html - 1;\r
130 -                               $temp_message .= substr($message, $end_html + 1, $grab_length);\r
131 -\r
132 -                               if ( $end_html = strpos($message, '>', $start_html) )\r
133 -                               {\r
134 -                                       $length = $end_html - $start_html + 1;\r
135 -                                       $hold_string = substr($message, $start_html, $length);\r
136 -\r
137 -                                       if ( strrpos(' ' . $hold_string, '<') != 1 )\r
138 -                                       {\r
139 -                                               $end_html = $start_html + 1;\r
140 -                                               $end_counter = 1;\r
141 -\r
142 -                                               while ( $end_counter && $end_html < strlen($message) )\r
143 -                                               {\r
144 -                                                       if ( substr($message, $end_html, 1) == '>' )\r
145 -                                                       {\r
146 -                                                               $end_counter--;\r
147 -                                                       }\r
148 -                                                       else if ( substr($message, $end_html, 1) == '<' )\r
149 -                                                       {\r
150 -                                                               $end_counter++;\r
151 -                                                       }\r
152 -\r
153 -                                                       $end_html++;\r
154 -                                               }\r
155 -\r
156 -                                               $length = $end_html - $start_html + 1;\r
157 -                                               $hold_string = substr($message, $start_html, $length);\r
158 -                                               $hold_string = str_replace('<!-- #sh -->', '', $hold_string);\r
159 -                                               $hold_string = str_replace('<!-- #eh -->', '', $hold_string);\r
160 -                                       }\r
161 -                                       else if ( $hold_string == '<!-- #sh -->' )\r
162 -                                       {\r
163 -                                               $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);\r
164 -                                       }\r
165 -                                       else if ( $hold_string == '<!-- #eh -->' )\r
166 -                                       {\r
167 -                                               $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);\r
168 -                                       }\r
169 -\r
170 -                                       $temp_message .= $hold_string;\r
171 -\r
172 -                                       $start_html += $length;\r
173 -                               }\r
174 -                               else\r
175 -                               {\r
176 -                                       $start_html = strlen($message);\r
177 -                               }\r
178 -                       }\r
179 -\r
180 -                       $grab_length = strlen($message) - $end_html - 1;\r
181 -                       $temp_message .= substr($message, $end_html + 1, $grab_length);\r
182 -\r
183 -                       $message = trim($temp_message);\r
184 -               }\r
185 -               else\r
186 -               {\r
187 -                       $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);\r
188 -               }\r
189 +               // This was shamelessly 'borrowed' from volker at multiartstudio dot de\r
190 +               // via php.net's annotated manual\r
191 +               $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se',"preg_replace('#\b(" . $highlight_match . ")\b#i', '<span style=\"color:#" . $theme['fontcolor3']. "\"><b>\\\\1</b></span>', '\\0')", '>' . $message . '<'), 1, -1));\r
192         }\r
193 -\r
194 +       \r
195         //\r
196         // Replace naughty words\r
197         //\r
198 @@ -1246,4 +1177,4 @@
199  \r
200  include($phpbb_root_path . 'includes/page_tail.'.$phpEx);\r
201  \r
202 -?>
203 \ No newline at end of file
204 +?>\r
This page took 0.368287 seconds and 3 git commands to generate.