[vlc-devel] [PATCH] network: fix clamping (cid #1420607)

Tristan Matthews tmatth at videolan.org
Mon Nov 6 22:28:14 CET 2017


On Mon, Nov 6, 2017 at 3:56 AM, Rémi Denis-Courmont <remi at remlab.net> wrote:
> Le 6 novembre 2017 07:21:27 GMT+02:00, Tristan Matthews <tmatth at videolan.org> a écrit :
>>---
>> src/network/tcp.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>>diff --git a/src/network/tcp.c b/src/network/tcp.c
>>index bc2a116532..51b275d238 100644
>>--- a/src/network/tcp.c
>>+++ b/src/network/tcp.c
>>@@ -177,9 +177,7 @@ int net_Connect( vlc_object_t *p_this, const char
>>*psz_host, int i_port,
>>
>>                 if (deadline != VLC_TS_INVALID)
>>                 {
>>-                    ms = (deadline - mdate()) / (CLOCK_FREQ / 1000);
>>-                    if (ms > INT_MAX)
>>-                        ms = INT_MAX;
>>+                    ms = __MIN((deadline - mdate()) / (CLOCK_FREQ /
>>1000), INT_MAX);
>>                 }
>>
>>                 val = vlc_poll_i11e(&ufd, 1, ms);
>>--
>>2.15.0
>>
>>_______________________________________________
>>vlc-devel mailing list
>>To unsubscribe or modify your subscription options:
>>https://mailman.videolan.org/listinfo/vlc-devel
>
> This is wrong because the macro is not expansion-safe.

Ok, should ms simply be a wider type then?

> Also, it attempts to solve a different issue than the one Coverity found.

I don't follow, the issue Coverity complained about was "ms > INT_MAX"
not making sense, since ms is an int. So you can clamp before writing
to ms (what I was trying to do) or for example, make ms a wider type,
clamp after assigning it and cast to int when calling vlc_poll_i11e.
The latter seemed grosser, but I didn't consider the expansion issue
with __MIN.

Best,
Tristan

> --
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list