Ver código fonte

Add some range checking.

Change-Id: I907f185d82fb4f7273eb5341acd100815688c4f2
Fixes-issue: CLIENT-406
Reviewed-on: http://gerrit.dmdirc.com/2813
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 anos atrás
pai
commit
1130b835a6

+ 11
- 5
src/com/dmdirc/parser/irc/Process004005.java Ver arquivo

@@ -123,21 +123,27 @@ public class Process004005 extends IRCProcessor {
123 123
         int i = multiParam ? 4 : 1;
124 124
         final String[] bits = multiParam ? token : token[3].split(" ");
125 125
 
126
-        parser.h005Info.put("004IRCD", bits[i++]);
126
+        if (bits.length > i) {
127
+            parser.h005Info.put("004IRCD", bits[i]);
128
+            i++;
129
+        }
127 130
 
128
-        if (bits[i].matches("^\\d+$")) {
131
+        if (bits.length > i && bits[i].matches("^\\d+$")) {
129 132
             // some IRCDs put a timestamp where the usermodes should be
130 133
             // (issues 4140. 4181 and 4183) so check to see if this is
131 134
             // numeric only, and if so, skip it.
132 135
             i++;
133 136
         }
134 137
 
135
-        parser.h005Info.put("USERMODES", bits[i++]);
136
-        parser.h005Info.put("USERCHANMODES", bits[i++]);
138
+        if (bits.length > i + 1) {
139
+            parser.h005Info.put("USERMODES", bits[i]);
140
+            parser.h005Info.put("USERCHANMODES", bits[i + 1]);
141
+            i += 2;
142
+        }
137 143
 
138 144
         if (bits.length > i) {
139 145
             // INSPIRCD includes an extra param
140
-            parser.h005Info.put("USERCHANPARAMMODES", bits[i++]);
146
+            parser.h005Info.put("USERCHANPARAMMODES", bits[i]);
141 147
         }
142 148
 
143 149
         parser.parseUserModes();

+ 4
- 1
test/com/dmdirc/parser/irc/Process004005Test.java Ver arquivo

@@ -22,11 +22,14 @@
22 22
 
23 23
 package com.dmdirc.parser.irc;
24 24
 
25
-import com.dmdirc.parser.common.ParserError;
26 25
 import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.parser.common.ParserError;
27 27
 import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
28
+
28 29
 import java.util.Date;
30
+
29 31
 import org.junit.Test;
32
+
30 33
 import static org.junit.Assert.*;
31 34
 import static org.mockito.Mockito.*;
32 35
 

Carregando…
Cancelar
Salvar