From patchwork Sat Jan 4 17:07:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Roth?= X-Patchwork-Id: 3433841 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E47DEC02DC for ; Sat, 4 Jan 2014 17:09:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1463D20158 for ; Sat, 4 Jan 2014 17:09:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36E5720145 for ; Sat, 4 Jan 2014 17:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754739AbaADRJG (ORCPT ); Sat, 4 Jan 2014 12:09:06 -0500 Received: from mail-ea0-f175.google.com ([209.85.215.175]:36450 "EHLO mail-ea0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754491AbaADRIo (ORCPT ); Sat, 4 Jan 2014 12:08:44 -0500 Received: by mail-ea0-f175.google.com with SMTP id z10so7149202ead.20 for ; Sat, 04 Jan 2014 09:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=DusXUOB4XiP8YBC/jB1QCQktKs/VV2Rx514IdapeYM0=; b=xu8j3e3mcGLz3EdTGYoi5emtCLEvQxU8ik8zzT4lw74+egbhvo810VusVEgfmpJcw+ TlT9HstziJ9dgBYCjc8oetNNZnyeyLAhuynzZig1ltZoErwZZgxTXrubdF0llgOf8rL5 WZf+243/GebaUXs4wK/aH+bKb+Tp9rU7cgYW6xw8XezzV30+TzQFIQAPXdb4yjaQYZP8 /qewH5abH5eyXwzJRJxtrAnFm4Jv2jCYFsW0OaHnQLNbn75aAEmaBmT1dr+listlngsY VroKYPjDT6ZN6pL6RdyfOGmXElq3HvP/PHjPClIOJ4ztPMbqI0BgiTAqkTqCKr3+s4J4 8EpA== X-Received: by 10.14.108.6 with SMTP id p6mr26666081eeg.31.1388855323181; Sat, 04 Jan 2014 09:08:43 -0800 (PST) Received: from exciton.exnihilo. (140-227.61-188.cust.bluewin.ch. [188.61.227.140]) by mx.google.com with ESMTPSA id e3sm155011641eeg.11.2014.01.04.09.08.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jan 2014 09:08:42 -0800 (PST) From: =?UTF-8?q?Andr=C3=A9=20Roth?= To: linux-media@vger.kernel.org Cc: =?UTF-8?q?Andr=C3=A9=20Roth?= Subject: [PATCH 05/11] libdvbv5: fix PMT parser Date: Sat, 4 Jan 2014 18:07:55 +0100 Message-Id: <1388855282-19295-5-git-send-email-neolynx@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1388855282-19295-1-git-send-email-neolynx@gmail.com> References: <1388855282-19295-1-git-send-email-neolynx@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: André Roth --- lib/include/libdvbv5/pmt.h | 6 +++++- lib/libdvbv5/descriptors/pmt.c | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/include/libdvbv5/pmt.h b/lib/include/libdvbv5/pmt.h index f1b7cef..a2183ac 100644 --- a/lib/include/libdvbv5/pmt.h +++ b/lib/include/libdvbv5/pmt.h @@ -96,9 +96,13 @@ struct dvb_table_pmt { uint16_t reserved3:4; } __attribute__((packed)); } __attribute__((packed)); + struct dvb_desc *descriptor; struct dvb_table_pmt_stream *stream; } __attribute__((packed)); +#define dvb_pmt_field_first header +#define dvb_pmt_field_last descriptor + #define dvb_pmt_stream_foreach(_stream, _pmt) \ for (struct dvb_table_pmt_stream *_stream = _pmt->stream; _stream; _stream = _stream->next) \ @@ -108,7 +112,7 @@ struct dvb_v5_fe_parms; extern "C" { #endif -void dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length); +void dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length); void dvb_table_pmt_free(struct dvb_table_pmt *pmt); void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, const struct dvb_table_pmt *pmt); diff --git a/lib/libdvbv5/descriptors/pmt.c b/lib/libdvbv5/descriptors/pmt.c index 3915414..5d42eb7 100644 --- a/lib/libdvbv5/descriptors/pmt.c +++ b/lib/libdvbv5/descriptors/pmt.c @@ -26,10 +26,9 @@ #include /* memcpy */ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, - ssize_t buflen, uint8_t *table, ssize_t *table_length) + ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length) { const uint8_t *p = buf, *endbuf = buf + buflen - 4; - struct dvb_table_pmt *pmt = (void *)table; struct dvb_table_pmt_stream **head = &pmt->stream; size_t size; @@ -38,13 +37,13 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, while (*head != NULL) head = &(*head)->next; } else { - size = offsetof(struct dvb_table_pmt, stream); + size = offsetof(struct dvb_table_pmt, dvb_pmt_field_last); if (p + size > endbuf) { dvb_logerr("PMT table was truncated. Need %zu bytes, but has only %zu.", size, buflen); return; } - memcpy(table, p, size); + memcpy(pmt, p, size); p += size; *table_length = sizeof(struct dvb_table_pmt); @@ -52,7 +51,8 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, bswap16(pmt->bitfield2); pmt->stream = NULL; - /* skip prog section */ + dvb_parse_descriptors(parms, p, pmt->prog_length, + &pmt->descriptor); p += pmt->prog_length; } @@ -74,15 +74,22 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, *head = stream; head = &(*head)->next; + if (stream->section_length > endbuf - p) { + dvb_logerr("PMT stream section length > buffer: %zd", stream->section_length - (endbuf - p)); + stream->section_length = endbuf - p; + } /* get the descriptors for each program */ dvb_parse_descriptors(parms, p, stream->section_length, &stream->descriptor); p += stream->section_length; } - if (endbuf - p) - dvb_logerr("PAT table has %zu spurious bytes at the end.", + if (p < endbuf) + dvb_logerr("PMT table has %zu spurious bytes at the end.", endbuf - p); + if (p > endbuf) + dvb_logerr("PMT oops %zu ", + p - endbuf); } void dvb_table_pmt_free(struct dvb_table_pmt *pmt) @@ -94,6 +101,7 @@ void dvb_table_pmt_free(struct dvb_table_pmt *pmt) stream = stream->next; free(tmp); } + dvb_free_descriptors((struct dvb_desc **) &pmt->descriptor); free(pmt); }