--- /home/zoge/workfolder/wput/old/wput-0.6.2+git20130413/src/ftp.c	2013-07-15 06:05:50.000000000 +0800
+++ /home/zoge/workfolder/wput/wput-0.6.2+git20130413/src/ftp.c	2015-10-16 15:38:49.039841144 +0800
@@ -372,10 +372,12 @@
 			 * TODO NRV is enough, but maybe someone has time to play around... */
 			/* simply replace all \n by \r\n unless there is already an \n */
 			while( d < databuf + readbytes){
-				while ((p < convertbuf + DBUFSIZE) && (d < databuf + readbytes)){
-					if (*d == '\n' && *(d-1) != '\r'){
+				while ((p < convertbuf + sizeof(convertbuf)) && (d < databuf + readbytes)){
+					if (*d == '\n' && d != databuf && *(d-1) != '\r'){
 						*p++ = '\r';
 						crcount++;
+						if (p == convertbuf + sizeof(convertbuf))
+							break;
 					}
 					*p++ = *d++;
 				}
