From patchwork Wed Sep 18 00:03:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15124 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 99FA744A35B for ; Wed, 18 Sep 2019 03:11:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 74CD2688305; Wed, 18 Sep 2019 03:11:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 30554687FD1 for ; Wed, 18 Sep 2019 03:11:07 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id x2so419097wmj.2 for ; Tue, 17 Sep 2019 17:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jViYmfLubQf9t1J9hEjuQUueTIAL49EbZ9Nbgjv2BDU=; b=eVWLnNs1pqwalQMEcsU/PhnP1OvNRhH3FPlx1wf0pfPs08zWGbzwousUP4+EIut4oR oDkdzbBHZqOk2W0U8GBTSXrjrVtZEWmv+ZSBT08V0hvAdsoza8efFOh0zj2kXvJaO0N2 QcC65SQJJnJU0u4K37XRTNmrB2pUWbTCrJ0oz/laacVaOucM8QTeC/QJUgcJkv/0raiJ frYQXTcu3bzkWygDyL68uiG+l7est4DGIWOFI5i+LwfeZjBW3atEfF4eYkVZhWxJitUx wR6iAZqc1ZJ1MgQmyy2or8vt4Swt+1AWMkuTC0D1bG0xEhW18G2RQqIwVug6E5dP8voS vPhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jViYmfLubQf9t1J9hEjuQUueTIAL49EbZ9Nbgjv2BDU=; b=D+btn4vxNH9gK5Q0WC/6r1fFyEZpVZCtWi6d0rpdDC6yYHwDpIOwIu+PMIDDN1wAR4 9dyLW/bKHNyKXujDiw1N+Pp0Xa1KhiK4+XjD+H67ShobGT14Q+H6nBmKia+n511x3oiU pPWaUj6HTASlVA/siKP5Dheqls+2qb+e+oRi5olBpvjb5UKWJBGhw+AryG9wAXgzz0Kl 55AhLfS42ripJ1wIrVV1avbs0Vm+1dKdiIDk09ZRBaOt+Oh75BHHyJK+VUhUuR8APJp5 V7Aiys5NiLSKRzFIP/ht+xhpq9dNLO/zQMrDnLP/qLJNiz8I1lU4v8iIVq/Ifc2jdwmN A54Q== X-Gm-Message-State: APjAAAVBTXpgkHgNnzH8nZ3x8utriZ9dazVEOkQ4/69OlR1TbsKGwBPd nsw9XcYcC2+S5W964SIE6i8q0Uj2Pgk= X-Google-Smtp-Source: APXvYqx3Wjt3Knzlnkl79JEFomKScSxoZtf2MDn6ua7a2PB54ESW/dgWb5k1iIN19FaSbStqiL+mlg== X-Received: by 2002:a7b:cb4b:: with SMTP id v11mr450915wmj.58.1568765061997; Tue, 17 Sep 2019 17:04:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc0f857.dynamic.kabel-deutschland.de. [188.192.248.87]) by smtp.gmail.com with ESMTPSA id b22sm418434wmj.36.2019.09.17.17.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 17:04:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Sep 2019 02:03:58 +0200 Message-Id: <20190918000358.25258-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190916155502.17579-1-andreas.rheinhardt@gmail.com> References: <20190916155502.17579-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/encryption_info: Don't pass NULL to memcpy X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The pointer arguments to memcpy (and several other functions of the C standard library) are not allowed to be NULL, not even when the number of bytes to copy is zero. An AVEncryptionInitInfo's data pointer is explicitly allowed to be NULL and yet av_encryption_init_info_add_side_data unconditionally used it as a source pointer to copy from. This commit changes this so that copying is only done if the number of bytes to copy is > 0. Fixes ticket #8141 as well as a part of ticket #8150. Signed-off-by: Andreas Rheinhardt --- This is a slightly improved version (see the code). Furthermore, a typo in the commit message has been fixed. libavutil/encryption_info.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c index 812c704776..dd3fa71a44 100644 --- a/libavutil/encryption_info.c +++ b/libavutil/encryption_info.c @@ -331,8 +331,10 @@ uint8_t *av_encryption_init_info_add_side_data(const AVEncryptionInitInfo *info, memcpy(cur_buffer, cur_info->key_ids[i], cur_info->key_id_size); cur_buffer += cur_info->key_id_size; } - memcpy(cur_buffer, cur_info->data, cur_info->data_size); - cur_buffer += cur_info->data_size; + if (cur_info->data_size > 0) { + memcpy(cur_buffer, cur_info->data, cur_info->data_size); + cur_buffer += cur_info->data_size; + } } return buffer;