Commit 72037ca7 authored by rswindell's avatar rswindell
Browse files

Use JS_GetStringLength and JS_NewStringCopyN to allow strings containing \0

(ASCII 0) to be read from or written to sockets and files.
parent 6831f220
......@@ -246,6 +246,7 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(p->etx) {
cp=strchr(buf,p->etx);
if(cp) *cp=0;
len=strlen(buf);
}
if(p->rot13)
......@@ -264,11 +265,12 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(uulen>=0) {
free(buf);
buf=uubuf;
len=uulen;
} else
free(uubuf);
}
str = JS_NewStringCopyZ(cx, buf);
str = JS_NewStringCopyN(cx, buf, len);
free(buf);
......@@ -841,6 +843,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* uubuf=NULL;
int len; /* string length */
int tlen; /* total length to write (may be greater than len) */
JSString* str;
private_t* p;
*rval = JSVAL_FALSE;
......@@ -853,8 +856,9 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(p->fp==NULL)
return(JS_TRUE);
cp=JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
len=strlen(cp);
str = JS_ValueToString(cx, argv[0]);
cp = JS_GetStringBytes(str);
len = JS_GetStringLength(str);
if((p->uuencoded || p->b64encoded || p->yencoded)
&& len && (uubuf=malloc(len))!=NULL) {
......
......@@ -358,8 +358,8 @@ js_send(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
*rval = JSVAL_FALSE;
str = JS_ValueToString(cx, argv[0]);
cp=JS_GetStringBytes(str);
len=strlen(cp);
cp = JS_GetStringBytes(str);
len = JS_GetStringLength(str);
if(sendsocket(p->sock,cp,len)==len) {
dbprintf(FALSE, p, "sent %u bytes",len);
......@@ -394,7 +394,7 @@ js_sendto(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* data */
data_str = JS_ValueToString(cx, argv[0]);
cp = JS_GetStringBytes(data_str);
len = strlen(cp);
len = JS_GetStringLength(data_str);
/* address */
ip_str = JS_ValueToString(cx, argv[1]);
......@@ -566,7 +566,7 @@ js_recv(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
buf[len]=0;
str = JS_NewStringCopyZ(cx, buf);
str = JS_NewStringCopyN(cx, buf, len);
free(buf);
if(str==NULL)
return(JS_FALSE);
......@@ -659,7 +659,7 @@ js_recvfrom(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
buf[len]=0;
str = JS_NewStringCopyZ(cx, buf);
str = JS_NewStringCopyN(cx, buf, len);
free(buf);
if(str==NULL)
......@@ -730,7 +730,7 @@ js_peek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
buf[len]=0;
str = JS_NewStringCopyZ(cx, buf);
str = JS_NewStringCopyN(cx, buf, len);
free(buf);
if(str==NULL)
return(JS_FALSE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment