@@ -116,33 +116,63 @@ func (r *Reader) PeekPushNotificationName() (string, error) {
116
116
if buf [0 ] != RespPush {
117
117
return "" , fmt .Errorf ("redis: can't parse push notification: %q" , buf )
118
118
}
119
- // remove push notification type and length
120
- buf = buf [2 :]
119
+
120
+ if len (buf ) < 3 {
121
+ return "" , fmt .Errorf ("redis: can't parse push notification: %q" , buf )
122
+ }
123
+
124
+ // remove push notification type
125
+ buf = buf [1 :]
126
+ // remove first line - e.g. >2\r\n
121
127
for i := 0 ; i < len (buf )- 1 ; i ++ {
122
128
if buf [i ] == '\r' && buf [i + 1 ] == '\n' {
123
129
buf = buf [i + 2 :]
124
130
break
131
+ } else {
132
+ if buf [i ] < '0' || buf [i ] > '9' {
133
+ return "" , fmt .Errorf ("redis: can't parse push notification: %q" , buf )
134
+ }
125
135
}
126
136
}
137
+ if len (buf ) < 2 {
138
+ return "" , fmt .Errorf ("redis: can't parse push notification: %q" , buf )
139
+ }
140
+ // next line should be $<length><string>\r\n or +<length><string>\r\n
127
141
// should have the type of the push notification name and it's length
128
- if buf [0 ] != RespString {
142
+ if buf [0 ] != RespString && buf [ 0 ] != RespStatus {
129
143
return "" , fmt .Errorf ("redis: can't parse push notification name: %q" , buf )
130
144
}
131
- // skip the length of the string
132
- for i := 0 ; i < len (buf )- 1 ; i ++ {
133
- if buf [i ] == '\r' && buf [i + 1 ] == '\n' {
134
- buf = buf [i + 2 :]
135
- break
145
+ typeOfName := buf [0 ]
146
+ // remove the type of the push notification name
147
+ buf = buf [1 :]
148
+ if typeOfName == RespString {
149
+ // remove the length of the string
150
+ if len (buf ) < 2 {
151
+ return "" , fmt .Errorf ("redis: can't parse push notification name: %q" , buf )
152
+ }
153
+ for i := 0 ; i < len (buf )- 1 ; i ++ {
154
+ if buf [i ] == '\r' && buf [i + 1 ] == '\n' {
155
+ buf = buf [i + 2 :]
156
+ break
157
+ } else {
158
+ if buf [i ] < '0' || buf [i ] > '9' {
159
+ return "" , fmt .Errorf ("redis: can't parse push notification name: %q" , buf )
160
+ }
161
+ }
136
162
}
137
163
}
138
164
165
+ if len (buf ) < 2 {
166
+ return "" , fmt .Errorf ("redis: can't parse push notification name: %q" , buf )
167
+ }
139
168
// keep only the notification name
140
169
for i := 0 ; i < len (buf )- 1 ; i ++ {
141
170
if buf [i ] == '\r' && buf [i + 1 ] == '\n' {
142
171
buf = buf [:i ]
143
172
break
144
173
}
145
174
}
175
+
146
176
return util .BytesToString (buf ), nil
147
177
}
148
178
0 commit comments