diff mbox series

[FFmpeg-devel] lavc/libx264.c: Fix possible UB by NULL pointer LHS

Message ID 23aa6fad-bd13-6aeb-cc27-8b2bd3497b8d@mail.de
State Accepted
Commit 0aa5dd084b8e26c9d644354c42c9252cf3b19cea
Headers show
Series [FFmpeg-devel] lavc/libx264.c: Fix possible UB by NULL pointer LHS | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Thilo Borgmann June 16, 2022, 3:58 p.m. UTC
Hi,

the LHS pointer might be NULL so that += would be UB.

Thanks,
Thilo
From cfb7ce8092c34436fae3120645aa96fe082af4ea Mon Sep 17 00:00:00 2001
From: Michael Goulet <mgoulet@fb.com>
Date: Thu, 16 Jun 2022 17:52:56 +0200
Subject: [PATCH] lavc/libx264.c: Fix possible UB by NULL pointer LHS

It is UB to attempt to do pointer arithmetic on NULL pointer LHS, even if that pointer arithmetic ends up being "+= 0" (i.e. !!p == 0 if p == NULL).
---
 libavcodec/libx264.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer June 16, 2022, 8:01 p.m. UTC | #1
On Thu, Jun 16, 2022 at 05:58:09PM +0200, Thilo Borgmann wrote:
> Hi,
> 
> the LHS pointer might be NULL so that += would be UB.
> 
> Thanks,
> Thilo

>  libx264.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 558de1ca7a30aa728193297a7d605c051b5bbfc0  0001-lavc-libx264.c-Fix-possible-UB-by-NULL-pointer-LHS.patch
> From cfb7ce8092c34436fae3120645aa96fe082af4ea Mon Sep 17 00:00:00 2001
> From: Michael Goulet <mgoulet@fb.com>
> Date: Thu, 16 Jun 2022 17:52:56 +0200
> Subject: [PATCH] lavc/libx264.c: Fix possible UB by NULL pointer LHS
> 
> It is UB to attempt to do pointer arithmetic on NULL pointer LHS, even if that pointer arithmetic ends up being "+= 0" (i.e. !!p == 0 if p == NULL).
> ---
>  libavcodec/libx264.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

should be ok

[...]

thx
Thilo Borgmann June 20, 2022, 9:09 a.m. UTC | #2
Am 16.06.22 um 22:01 schrieb Michael Niedermayer:
> On Thu, Jun 16, 2022 at 05:58:09PM +0200, Thilo Borgmann wrote:
>> Hi,
>>
>> the LHS pointer might be NULL so that += would be UB.
>>
>> Thanks,
>> Thilo
> 
>>   libx264.c |    4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>> 558de1ca7a30aa728193297a7d605c051b5bbfc0  0001-lavc-libx264.c-Fix-possible-UB-by-NULL-pointer-LHS.patch
>>  From cfb7ce8092c34436fae3120645aa96fe082af4ea Mon Sep 17 00:00:00 2001
>> From: Michael Goulet <mgoulet@fb.com>
>> Date: Thu, 16 Jun 2022 17:52:56 +0200
>> Subject: [PATCH] lavc/libx264.c: Fix possible UB by NULL pointer LHS
>>
>> It is UB to attempt to do pointer arithmetic on NULL pointer LHS, even if that pointer arithmetic ends up being "+= 0" (i.e. !!p == 0 if p == NULL).
>> ---
>>   libavcodec/libx264.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> should be ok

Pushed, thanks!

-Thilo
diff mbox series

Patch

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 14177b3016..616d855067 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -940,7 +940,9 @@  static av_cold int X264_init(AVCodecContext *avctx)
                     return ret;
             }
             p= strchr(p, ':');
-            p+=!!p;
+            if (p) {
+                ++p;
+            }
         }
     }