From patchwork Fri Jun 29 21:19:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander 'lynxis' Couzens X-Patchwork-Id: 937168 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=fe80.eu Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rgl44mXO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="a2GWnl5j"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41HV0N1tzvz9s29 for ; Sat, 30 Jun 2018 07:19:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=hhsT1Ak0yRuU2EW4ZeTQ1/sSV6QrXhK0EvKnaRkKEuQ=; b=rgl44mXOpoiZz4 wwJGQHAhQGFeWo4V4vOfsgMOvbDTcAdCWHcGlC8Yvss/pqT+gHAH/Osn5BgpdAEgeqASW3Eetwqog AQMMDvicLukFS79B6w3O67wFW9Kd1nhtqHgg3Ki8bqbZqf+QMDwmRoNsfiguxMUSOIHxsnDBm+r9C 1yqV/Dn/mv8o4eir75F3HhjOlpG88sbeno2F30GbHZW7tqSbgcxm089Cj9z3lHImCXk0Um9uKX8df zqqpgaSaJvwOnK2fZTVb793bpMui9SlYUoj7T9XOlM2i79uAgmTM98CPRcM8uCP+7+745GE/gcb6X u8uDAieRDrJqd7sr/vCA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZ0np-00079g-3R; Fri, 29 Jun 2018 21:19:37 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZ0nn-00079T-Cj for openwrt-devel@bombadil.infradead.org; Fri, 29 Jun 2018 21:19:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dQbPPx8YLmSfG3FftnR0PF3IuFP4pdTFFjerbKgXs7Y=; b=a2GWnl5jSdyOgFBhbXrGK5wU8 CljRKZIPakXZq192Tcb/hmYRxL9CMdAUtDxEZv7V+NanqN2jMP64SuEE3nGCdfJbG5iKbd1q2Il+9 WGat1MC8PZu7td5DceGgPFHEbNWU4Nkr3CAkwTq+juc/HRH1SygFT1ikODd3nUbSFdMJS11EGiDjW 07GUFcFBP76VjPFah5eNdkPKsTjg3CoDu9vQ2TnBx9+g4pEwNNjwG+xQzfagnJ6/vpPY5PMsc3adB zx/R/Gs6w/46yQrM2kVIwIcsbr5UcLrc4yDyC5tdWYgN6eQWm5Dru6VCq0HnZwsoQZ1dJpnqneAx8 /ZgsvHazQ==; Received: from mail.base45.de ([2001:67c:2050:320::77]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZ0nk-0000W7-Dg for openwrt-devel@lists.openwrt.org; Fri, 29 Jun 2018 21:19:34 +0000 Received: from [91.64.56.113] (helo=lazus.yip) by mail.base45.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1fZ0nZ-00035n-Ny; Fri, 29 Jun 2018 21:19:21 +0000 From: Alexander Couzens To: John Crispin Date: Fri, 29 Jun 2018 23:19:11 +0200 Message-Id: <20180629211912.27006-1-lynxis@fe80.eu> X-Mailer: git-send-email 2.18.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180629_221932_526623_CFD22140 X-CRM114-Status: UNSURE ( 9.35 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record Subject: [OpenWrt-Devel] [PATCH 1/2] nmea.c: Add null byte to nmea fields X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openwrt-devel@lists.openwrt.org, Alexander Couzens MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Either the main.c treat them as non-null terminated strings or nmea adds a null byte to the fields. Found-by: Coverity Fixes CID 1431321 1431098 --- nmea.c | 12 ++++++------ nmea.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nmea.c b/nmea.c index 73ee722dfb7e..242bc21eda59 100644 --- a/nmea.c +++ b/nmea.c @@ -51,7 +51,7 @@ struct nmea_param { } nmea_params[MAX_NMEA_PARAM]; static int nmea_bad_time; -char longitude[32] = { 0 }, latitude[32] = { 0 }, course[16] = { 0 }, speed[16] = { 0 }, elevation[16] = { 0 }; +char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 }; int gps_valid = 0; static void @@ -136,8 +136,8 @@ nmea_rmc_cb(void) if (*nmea_params[6].str == 'W') lon *= -1.0; - snprintf(latitude, sizeof(latitude), "%f", lat); - snprintf(longitude, sizeof(longitude), "%f", lon); + snprintf(latitude, sizeof(latitude) - 1, "%f", lat); + snprintf(longitude, sizeof(longitude) - 1, "%f", lon); DEBUG(3, "position: %s %s\n", latitude, longitude); gps_timestamp(); @@ -149,7 +149,7 @@ nmea_gga_cb(void) { if (!gps_valid) return; - strncpy(elevation, nmea_params[9].str, sizeof(elevation)); + strncpy(elevation, nmea_params[9].str, sizeof(elevation) - 1); DEBUG(4, "height: %s\n", elevation); } @@ -158,8 +158,8 @@ nmea_vtg_cb(void) { if (!gps_valid) return; - strncpy(course, nmea_params[1].str, sizeof(course)); - strncpy(speed, nmea_params[7].str, sizeof(speed)); + strncpy(course, nmea_params[1].str, sizeof(course) - 1); + strncpy(speed, nmea_params[7].str, sizeof(speed) - 1); DEBUG(4, "course: %s\n", course); DEBUG(4, "speed: %s\n", speed); } diff --git a/nmea.h b/nmea.h index c6f1896df986..9f46d299983e 100644 --- a/nmea.h +++ b/nmea.h @@ -23,7 +23,7 @@ #include -extern char longitude[32], latitude[32], course[16], speed[16], elevation[16]; +extern char longitude[33], latitude[33], course[17], speed[17], elevation[17]; extern int nmea_open(char *dev, struct ustream_fd *s, speed_t speed); extern void gps_timestamp(void); extern unsigned int adjust_clock;