From 027ca1c67cf5ece3c2b4ca367df2e2d0075ff582 Mon Sep 17 00:00:00 2001 From: mikespook Date: Thu, 27 Dec 2012 12:32:41 +0800 Subject: [PATCH] too few data to unpack, read more --- worker/agent.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/worker/agent.go b/worker/agent.go index 65e3905..d015e55 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -137,11 +137,14 @@ BEGIN: } // split package tl := len(data) - if tl < 12 { + if tl < 12 { // too few data to unpack, read more goto BEGIN } start := 0 - for i := 0; i < tl; i++ { + for i := 0; i < tl - 12; i++ { + if start + 12 > tl { // too few data to unpack, read more + goto BEGIN + } if string(data[start:start+4]) == common.RES_STR { l := int(common.BytesToUint32([4]byte{data[start+8], data[start+9], data[start+10], data[start+11]})) @@ -155,10 +158,11 @@ BEGIN: } else { // ops! It won't be possible. goto BEGIN } - } else { + } else { // flag was not found, move to next step start++ } } + goto BEGIN return nil, common.Errorf("Invalid data: %V", data) }