Procházet zdrojové kódy

fixed out of buffer write in utf8/16 convert

ncannasse před 7 roky
rodič
revize
71e1b6d33d
4 změnil soubory, kde provedl 4 přidání a 5 odebrání
  1. 1 1
      libs/ssl/ssl.c
  2. 1 1
      src/code.c
  3. 0 1
      src/std/date.c
  4. 2 2
      src/std/string.c

+ 1 - 1
libs/ssl/ssl.c

@@ -86,7 +86,7 @@ static int ssl_error(int ret) {
 	char buf[128];
 	char buf[128];
 	uchar buf16[128];
 	uchar buf16[128];
 	mbedtls_strerror(ret, buf, sizeof(buf));
 	mbedtls_strerror(ret, buf, sizeof(buf));
-	hl_from_utf8(buf16, (int)strlen(buf) + 1, buf);
+	hl_from_utf8(buf16, (int)strlen(buf), buf);
 	hl_error_msg(buf16);
 	hl_error_msg(buf16);
 	return ret;
 	return ret;
 }
 }

+ 1 - 1
src/code.c

@@ -135,7 +135,7 @@ const uchar *hl_get_ustring( hl_code *code, int index ) {
 	if( str == NULL ) {
 	if( str == NULL ) {
 		int size = hl_utf8_length((vbyte*)code->strings[index],0);
 		int size = hl_utf8_length((vbyte*)code->strings[index],0);
 		str = hl_malloc(&code->alloc,(size+1)<<1);
 		str = hl_malloc(&code->alloc,(size+1)<<1);
-		hl_from_utf8(str,size+1,code->strings[index]);
+		hl_from_utf8(str,size,code->strings[index]);
 		code->ustrings[index] = str;
 		code->ustrings[index] = str;
 	}
 	}
 	return str;
 	return str;

+ 0 - 1
src/std/date.c

@@ -60,7 +60,6 @@ HL_PRIM vbyte *hl_date_to_string( int date, int *len ) {
 	size = (int)strftime(buf,127,"%Y-%m-%d %H:%M:%S",&t);
 	size = (int)strftime(buf,127,"%Y-%m-%d %H:%M:%S",&t);
 	out = (uchar*)hl_gc_alloc_noptr((size + 1) << 1);
 	out = (uchar*)hl_gc_alloc_noptr((size + 1) << 1);
 	hl_from_utf8(out,size,buf);
 	hl_from_utf8(out,size,buf);
-	out[size] = 0;
 	*len = size;
 	*len = size;
 	return (vbyte*)out;
 	return (vbyte*)out;
 }
 }

+ 2 - 2
src/std/string.c

@@ -127,14 +127,14 @@ HL_PRIM int hl_from_utf8( uchar *out, int outLen, const char *str ) {
 HL_PRIM uchar *hl_to_utf16( const char *str ) {
 HL_PRIM uchar *hl_to_utf16( const char *str ) {
 	int len = hl_utf8_length((vbyte*)str,0);
 	int len = hl_utf8_length((vbyte*)str,0);
 	uchar *out = (uchar*)hl_gc_alloc_noptr((len + 1) * sizeof(uchar));
 	uchar *out = (uchar*)hl_gc_alloc_noptr((len + 1) * sizeof(uchar));
-	hl_from_utf8(out,len+1,str);
+	hl_from_utf8(out,len,str);
 	return out;
 	return out;
 }
 }
 
 
 HL_PRIM vbyte* hl_utf8_to_utf16( vbyte *str, int pos, int *size ) {
 HL_PRIM vbyte* hl_utf8_to_utf16( vbyte *str, int pos, int *size ) {
 	int ulen = hl_utf8_length(str, pos);
 	int ulen = hl_utf8_length(str, pos);
 	uchar *s = (uchar*)hl_gc_alloc_noptr((ulen + 1)*sizeof(uchar));
 	uchar *s = (uchar*)hl_gc_alloc_noptr((ulen + 1)*sizeof(uchar));
-	hl_from_utf8(s,ulen+1,(char*)(str+pos));
+	hl_from_utf8(s,ulen,(char*)(str+pos));
 	*size = ulen << 1;
 	*size = ulen << 1;
 	return (vbyte*)s;
 	return (vbyte*)s;
 }
 }