diff --git a/src/sbbs3/js_global.c b/src/sbbs3/js_global.c index d63f4268f52604298c5fe67543bd65c3f9cdc99e..1883d4f8371e3bd31f494e5ead09d3683d984591 100644 --- a/src/sbbs3/js_global.c +++ b/src/sbbs3/js_global.c @@ -608,7 +608,7 @@ js_lfexpand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return(JS_TRUE); } -static int get_prefix(char *text, int *bytes, int *len) +static int get_prefix(char *text, int *bytes, int *len, int maxlen) { int tmp_prefix_bytes,tmp_prefix_len; int expect; @@ -676,6 +676,9 @@ static int get_prefix(char *text, int *bytes, int *len) break; } } + if(*bytes >= maxlen) { + lprintf(LOG_CRIT, "Prefix bytes %u is larger than buffer (%u) here: %*.*s",*bytes,maxlen,maxlen,maxlen,text); + } return(depth); } @@ -762,7 +765,7 @@ js_word_wrap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) /* Get prefix from the first line (ouch) */ l=0; i=0; - if(handle_quotes && (quote_count=get_prefix(inbuf, &prefix_bytes, &prefix_len))) { + if(handle_quotes && (quote_count=get_prefix(inbuf, &prefix_bytes, &prefix_len, len*2+2))) { i+=prefix_bytes; if(prefix_len>len/3*2) { /* This prefix is insane (more than 2/3rds of the new width) hack it down to size */ @@ -786,7 +789,7 @@ js_word_wrap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) crcount++; break; case '\n': - if(handle_quotes && (quote_count=get_prefix(inbuf+i+1, &prefix_bytes, &prefix_len))) { + if(handle_quotes && (quote_count=get_prefix(inbuf+i+1, &prefix_bytes, &prefix_len, len*2+2))) { /* Move the input pointer offset to the last char of the prefix */ i+=prefix_bytes; }