Re: [Evolution-hackers] camel/camel-folder-summary.c: Understanding `bdata_extract_digit ()`



On Mon, 2012-12-31 at 13:21 +0100, Paul Menzel wrote:
> analyzing crashes, I see that in `./camel/camel-folder-summary.c`
> 
>         count = bdata_extract_digit (&part)
> 
> sometimes seems to be negative, which seems unreasonable. I added
> `g_assert (count < 0)` right after that and in at least one case I hit
> that assert. Though this is not reproducible.

	Hi,
the BDATA column is for the provider, it can encode anything there, the
functions just help to decode values in a convenient and consistent way.
I do not know why you got a negative count, either there's something
wrong in your folders.db file, or a use-after-free occurred.

> The next check checks again, if the string exists and should be
> redundant to `if (!part)`.
> 
> 	        if (!**part)
> 		        return 0;

Nope, it is not redundant, it checks whether this is the end of the
string (thus there is no need to read further from it), after a shift by
the space.

> Now `strtoul()` is used to convert the string to an unsigned long int.
> 
> 	        return strtoul (*part, part, 10);
> 
> Could this cause problems because `count` is a normal integer and not an
> unsigned integer?

Only if the string has stored large enough number. I guess it's not the
case here.

> Also I do not understand why we check for a space because according to
> `man strtoul` spaces are skipped.

It's for consistency, because it's a good practice to read what you
wrote.
	Hope it helps,
	Milan



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