Skip to contentSkip to conversation

Avoid buffer overflow with UTF-8 32-bit strings

PATCH New Mauro Carvalho Chehab 1 participant 1 message Apr 12, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid buffer overflow with UTF-8 32-bit strings

As Winfried <[email protected]> pointed, me UTF-8 can have up to 32 bits.

Also, someone might want to convert data to UCS-4, So, the buffer need to have 4 bytes per char, to be safe.

util/scan/scan.c +1 -1
@@ -884,7 +884,7 @@ static void descriptorcpy(char **dest, c
 	 * Destination length should be bigger. As the worse case seems to
 	 * use 3 chars for one code, use it for destlen
 	 */
-	destlen = len * 3;
+	destlen = len * 4;
 	*dest = malloc(destlen + 1);
 
 	/* Remove special chars */