bug-libunistring
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-libunistring] possible memory issue with u8_strconv_to_encoding


From: Patrice Dumas
Subject: Re: [bug-libunistring] possible memory issue with u8_strconv_to_encoding after u8_toupper
Date: Tue, 5 Sep 2023 16:26:10 +0200

On Tue, Sep 05, 2023 at 01:27:02PM +0200, Bruno Haible wrote:
> Hello Patrice,
> 
> The problem is that u8_strconv_to_encoding takes a NUL-terminated string
> as argument. However, in the preceding statement, u8_result does not contain
> a terminating NUL, since you did not ask for the terminating NUL of u8_text
> to be converted.
> 
> When you change
> 
>   u8_result = u8_toupper (u8_text, u8_strlen (u8_text),
>                           NULL, NULL, NULL, &lengthp);
> 
> to
> 
>   u8_result = u8_toupper (u8_text, u8_strlen (u8_text) + 1,
>                           NULL, NULL, NULL, &lengthp);
> 
> the problem goes away.

Indeed, thanks a lot.  I am not surprised that it was some stupid error
on my side.  Maybe there could be a word on that in the "Conventions"
node. After

All parameters starting with ‘str’ and the parameters of functions starting 
with u8_str/u16_str/u32_str denote a NUL terminated string. 

  there could be something like

The other functions do not treat NUL in string especially, so you should
inlude it explicitely in your string, by setting the length to strlen_un + 1.

What do you think?

-- 
Pat



reply via email to

[Prev in Thread] Current Thread [Next in Thread]