From patchwork Thu Jul 25 13:09:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Jasny X-Patchwork-Id: 2833395 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 E7BA2C0319 for ; Thu, 25 Jul 2013 13:10:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B5A8320214 for ; Thu, 25 Jul 2013 13:10:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4282E20201 for ; Thu, 25 Jul 2013 13:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755869Ab3GYNKl (ORCPT ); Thu, 25 Jul 2013 09:10:41 -0400 Received: from mail-bk0-f47.google.com ([209.85.214.47]:48547 "EHLO mail-bk0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755678Ab3GYNKj (ORCPT ); Thu, 25 Jul 2013 09:10:39 -0400 Received: by mail-bk0-f47.google.com with SMTP id jg1so668240bkc.6 for ; Thu, 25 Jul 2013 06:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Sstwz6lQFETbU85Np2rx00U5RvDQDOHM3eC2xrQ11LQ=; b=hTd/Cp9vtjRccli4vQx5sovunrTtxKI7gGyrxL2XrrsNbSZvcyUeZGPtXZuOAfBJ2p hyAcRsO3HdganWBMi+/GCorj2fCvztTcXzymE64x6pl0ABs4i4rtxCJ6U7zgbgJu60KP bpMiPSykUCjIGjzEL4rXtHxeNJ/CIqOYYEqRo37tcH4N81+ta/ieV9DS8d0DMtQhGysl A7+YLuPkH2Y3wL86eE+ndorRZLCxXF+DjPVfblbPd/Wt5EjI6qr9nCqUcXtrJJoAFu53 gHUg/GOu8Q7rgo/8Bw+NqwSE7CMl3ItakLpED6CXVPulOVuGCxDNHr8h0zrSQN2+SNFZ xYNA== X-Received: by 10.205.130.67 with SMTP id hl3mr5956446bkc.61.1374757837384; Thu, 25 Jul 2013 06:10:37 -0700 (PDT) Received: from gjasny06.drs.expertcity.com ([78.108.113.8]) by mx.google.com with ESMTPSA id eu16sm10949773bkc.0.2013.07.25.06.10.36 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Jul 2013 06:10:36 -0700 (PDT) From: Gregor Jasny To: linux-media@vger.kernel.org Cc: Gregor Jasny , Hans Verkuil Subject: [PATCH 3/4] rds-ctl: Always terminate strings properly Date: Thu, 25 Jul 2013 15:09:33 +0200 Message-Id: <1374757774-29051-4-git-send-email-gjasny@googlemail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1374757774-29051-1-git-send-email-gjasny@googlemail.com> References: <1374757774-29051-1-git-send-email-gjasny@googlemail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 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 Detected by Coverity. Signed-off-by: Gregor Jasny CC: Hans Verkuil Reviewed-by: Hans Verkuil --- utils/rds-ctl/rds-ctl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp index a9fe2a8..74972eb 100644 --- a/utils/rds-ctl/rds-ctl.cpp +++ b/utils/rds-ctl/rds-ctl.cpp @@ -762,13 +762,11 @@ static int parse_cl(int argc, char **argv) params.options[(int)opt] = 1; switch (opt) { case OptSetDevice: - strncpy(params.fd_name, optarg, 80); + strncpy(params.fd_name, optarg, sizeof(params.fd_name)); if (optarg[0] >= '0' && optarg[0] <= '9' && strlen(optarg) <= 3) { - static char newdev[20]; - - sprintf(newdev, "/dev/radio%s", optarg); - strncpy(params.fd_name, newdev, 20); + snprintf(params.fd_name, sizeof(params.fd_name), "/dev/radio%s", optarg); } + params.fd_name[sizeof(params.fd_name) - 1] = '\0'; break; case OptSetFreq: params.freq = strtod(optarg, NULL); @@ -786,7 +784,8 @@ static int parse_cl(int argc, char **argv) { if (access(optarg, F_OK) != -1) { params.filemode_active = true; - strncpy(params.fd_name, optarg, 80); + strncpy(params.fd_name, optarg, sizeof(params.fd_name)); + params.fd_name[sizeof(params.fd_name) - 1] = '\0'; } else { fprintf(stderr, "Unable to open file: %s\n", optarg); return -1; @@ -1006,7 +1005,8 @@ int main(int argc, char **argv) fprintf(stderr, "No RDS-capable device found\n"); exit(1); } - strncpy(params.fd_name, devices[0].c_str(), 80); + strncpy(params.fd_name, devices[0].c_str(), sizeof(params.fd_name)); + params.fd_name[sizeof(params.fd_name) - 1] = '\0'; printf("Using device: %s\n", params.fd_name); } if ((fd = test_open(params.fd_name, O_RDONLY | O_NONBLOCK)) < 0) {