@@ -31,7 +31,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
3131 if err != nil {
3232 errLog .Print (err )
3333 mc .Close ()
34- return nil , driver . ErrBadConn
34+ return nil , ErrInvalidConn
3535 }
3636
3737 // Packet Length [24 bit]
@@ -40,7 +40,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
4040 if pktLen < 1 {
4141 errLog .Print (ErrMalformPkt )
4242 mc .Close ()
43- return nil , driver . ErrBadConn
43+ return nil , ErrInvalidConn
4444 }
4545
4646 // Check Packet Sync [8 bit]
@@ -58,7 +58,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
5858 if err != nil {
5959 errLog .Print (err )
6060 mc .Close ()
61- return nil , driver . ErrBadConn
61+ return nil , ErrInvalidConn
6262 }
6363
6464 isLastPacket := (pktLen < maxPacketSize )
@@ -114,10 +114,14 @@ func (mc *mysqlConn) writePacket(data []byte) error {
114114 // Handle error
115115 if err == nil { // n != len(data)
116116 errLog .Print (ErrMalformPkt )
117- } else {
118- errLog .Print (err )
117+ return ErrMalformPkt
119118 }
120- return driver .ErrBadConn
119+ errLog .Print (err )
120+ if n == 0 && pktLen == len (data )- 4 {
121+ // first loop iteration, nothing was written
122+ return errNoWrite
123+ }
124+ return ErrInvalidConn
121125 }
122126}
123127
@@ -241,7 +245,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
241245 if data == nil {
242246 // can not take the buffer. Something must be wrong with the connection
243247 errLog .Print (ErrBusyBuffer )
244- return driver . ErrBadConn
248+ return ErrInvalidConn
245249 }
246250
247251 // ClientFlags [32 bit]
@@ -312,7 +316,7 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
312316 if data == nil {
313317 // can not take the buffer. Something must be wrong with the connection
314318 errLog .Print (ErrBusyBuffer )
315- return driver . ErrBadConn
319+ return ErrInvalidConn
316320 }
317321
318322 // Add the scrambled password [null terminated string]
@@ -334,7 +338,7 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error {
334338 if data == nil {
335339 // can not take the buffer. Something must be wrong with the connection
336340 errLog .Print (ErrBusyBuffer )
337- return driver . ErrBadConn
341+ return ErrInvalidConn
338342 }
339343
340344 // Add command byte
@@ -353,7 +357,7 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error {
353357 if data == nil {
354358 // can not take the buffer. Something must be wrong with the connection
355359 errLog .Print (ErrBusyBuffer )
356- return driver . ErrBadConn
360+ return ErrInvalidConn
357361 }
358362
359363 // Add command byte
@@ -374,7 +378,7 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error {
374378 if data == nil {
375379 // can not take the buffer. Something must be wrong with the connection
376380 errLog .Print (ErrBusyBuffer )
377- return driver . ErrBadConn
381+ return ErrInvalidConn
378382 }
379383
380384 // Add command byte
@@ -741,6 +745,10 @@ func (stmt *mysqlStmt) writeCommandLongData(paramID int, arg []byte) error {
741745 data = data [pktLen - dataOffset :]
742746 continue
743747 }
748+ if err == errNoWrite && argLen != len (arg ) {
749+ // must not relay errNoWrite after first loop iteration
750+ return ErrInvalidConn
751+ }
744752 return err
745753
746754 }
@@ -777,7 +785,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
777785 if data == nil {
778786 // can not take the buffer. Something must be wrong with the connection
779787 errLog .Print (ErrBusyBuffer )
780- return driver . ErrBadConn
788+ return ErrInvalidConn
781789 }
782790
783791 // command [1 byte]
0 commit comments