libks icon indicating copy to clipboard operation
libks copied to clipboard

kws_read_frame when receive a short ping frame

Open shanghaimoon888 opened this issue 2 years ago • 1 comments

Where the function kws_read_frame() read a ping frame which the frame length is 6(2 header and 4 payload) and followed with a text frame. Then the code below will make the kws->datalen to be 9: if ((kws->datalen = kws_string_read(kws, kws->buffer, 9 + 1, kws->block)) < 0) This will trigger the error in below code because the need will be -3: need = (kws->plen - (kws->datalen - need)); if (need < 0) { /* invalid read - protocol err .. */ ks_log(KS_LOG_ERROR, "Read frame error because need = %ld\n", need); *oc = WSOC_CLOSE; return kws_close(kws, WS_NONE); } I have modify the code to: if ((kws->datalen = kws_string_read(kws, kws->buffer, 6 + 1, kws->block)) < 0) and it seems worked. But if the ping frame length is less than 6, the error is still exist. What about a perfect solution?

shanghaimoon888 avatar Nov 29 '23 09:11 shanghaimoon888

https://github.com/signalwire/libks/pull/181

chucongqing avatar Dec 05 '23 02:12 chucongqing