Received: by 10.223.185.116 with SMTP id b49csp3171117wrg; Sun, 25 Feb 2018 15:57:04 -0800 (PST) X-Google-Smtp-Source: AH8x227WgvzXE/XnZRqucs4p33P1VM9Sd7mnlSa0I7ulHWoQaTKXRIY35857U8uuPIiYssuWIRgs X-Received: by 2002:a17:902:7808:: with SMTP id p8-v6mr8939880pll.161.1519603024075; Sun, 25 Feb 2018 15:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519603024; cv=none; d=google.com; s=arc-20160816; b=Lc4p2S13vVvXrpWn+xNdZWfTAK8hHSa2DWElCjttJeYEU02MTxEw99ZlJzezZBJKP/ RK3tbUbPZQ0jDAOoYQWnCCu4RxmMqHV+b0LWcyH18rsbgTgi0s9HVQE2C4wfkr+uxvag vLfQ+bdeFHx4sGTvzAY4NRr2m1+72CtnhUlgfGPSfsddKKZURc6OvmjWa6QcL+vv/iyl ugZu/mrjhYUcp6wb66zrU4Gj1F48ksNl2+fgA2FzwSs9azZQplRReKu3Guc5ADdx5e6h GaOfCKluL16qxFgl3Kuh40X9kdYE6DrCxIzU8omiXsSfTBlE6WedSveMU6nWMEEdoZym PtZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TFcfAB9n5wWoNih1MVgGj/uyhvWfOj1pRx1l3IJWwRM=; b=GbFCrdTuoT8YpxSzhGjecRpVK9eVYksakrTkXbHzdVw+uyD9cVcyeOe0ogvbVDaHCk BkCHNPPOf7dv63nJi9QUoLoapX3AS6ScjxJkjAhvkPQrYWqpe+PNf4LBSDkh0mwkQdzc GAp3Drwe6Z8uoyKjF6DrBIUg1Ee524tH6WwbeLocK/PPLjTMMCTk3bqpXnASKgPgoU8S /cpbRNMVkf27MMRg+XhrkD14LYkQsFmxExTp3cxUoFlKcFZqzD5e80qrmP32abU749mz mFom975wqYsTHJ9EuIY1DVzkMth7nZsrLrbjfM+9XnSkpTUCKohPtacJriPfYuz79kso dpqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si4736295pgc.243.2018.02.25.15.56.49; Sun, 25 Feb 2018 15:57:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752058AbeBYXz2 (ORCPT + 99 others); Sun, 25 Feb 2018 18:55:28 -0500 Received: from mxf98a.netcup.net ([46.38.249.138]:53032 "EHLO mxf98a.netcup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751967AbeBYXyw (ORCPT ); Sun, 25 Feb 2018 18:54:52 -0500 Received: from buildbert.robertabel.eu (x4d076501.dyn.telefonica.de [77.7.101.1]) by mxf98a.netcup.net (Postfix) with ESMTPSA id DFA8F1409D3; Mon, 26 Feb 2018 00:54:50 +0100 (CET) Authentication-Results: mxf98a; spf=pass (sender IP is 77.7.101.1) smtp.mailfrom=rabel@robertabel.eu smtp.helo=buildbert.robertabel.eu Received-SPF: pass (mxf98a: connection is authenticated) From: Robert Abel To: linux-kernel Cc: Robert Abel , Miguel Ojeda , Willy Tarreau , Geert Uytterhoeven , Andy Shevchenko Subject: [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands Date: Mon, 26 Feb 2018 00:54:31 +0100 Message-Id: <20180225235432.31209-4-rabel@robertabel.eu> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180225235432.31209-3-rabel@robertabel.eu> References: <9ec3c54c-f8fe-22d7-783e-8cf9862405bb@robertabel.eu> <20180225235432.31209-1-rabel@robertabel.eu> <20180225235432.31209-2-rabel@robertabel.eu> <20180225235432.31209-3-rabel@robertabel.eu> X-PPP-Message-ID: <20180225235451.31422.46656@mxf98a.netcup.net> X-PPP-Vhost: robertabel.eu Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org NUL-terminate each individual number to be parsed. To do this, the next command character and a pointer to its argument are found and stored. The command character is then overwritten by NUL before kstr* functions are called on the buffer. Signed-off-by: Robert Abel --- drivers/auxdisplay/charlcd.c | 53 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c index a3d364e6c666..24cabe88c7f0 100644 --- a/drivers/auxdisplay/charlcd.c +++ b/drivers/auxdisplay/charlcd.c @@ -471,28 +471,63 @@ static inline int handle_lcd_special_code(struct charlcd *lcd) break; } case 'x': /* gotoxy : LxXXX[yYYY]; */ - case 'y': /* gotoxy : LyYYY[xXXX]; */ + case 'y': { /* gotoxy : LyYYY[xXXX]; */ + + char* nxt_esc; + char nxt_cmd; + char cmd; + struct charlcd_priv_addr tmp_addr; + if (!strchr(esc, ';')) break; - while (*esc) { - if (*esc == 'x') { - esc++; - if (kstrtoul(esc, 10, &priv->addr.x) < 0) + /* sequence is processed whether legal or illegal */ + processed = 1; + + /* copy current address to temporary buffer */ + tmp_addr = priv->addr; + + nxt_cmd = *esc++; + nxt_esc = esc; + + while ('\0' != *esc) { + + cmd = nxt_cmd; + esc = nxt_esc; + nxt_esc = strpbrk(esc, "xy;"); + if (NULL != nxt_esc) { + nxt_cmd = *nxt_esc; + /* terminate current sequence with NUL */ + *nxt_esc++ = '\0'; + } + + if ('x' == cmd) { + if (kstrtoul(esc, 10, &tmp_addr.x) < 0) break; - } else if (*esc == 'y') { - esc++; - if (kstrtoul(esc, 10, &priv->addr.y) < 0) + } else if ('y' == cmd) { + if (kstrtoul(esc, 10, &tmp_addr.y) < 0) break; } else { + /* break on unknown command or ';' */ break; } + } + /* unknown commands in sequence will be followed by at least ';' */ + if ('\0' != *esc) + break; + + /* clamp new x/y coordinates */ + if (tmp_addr.x >= lcd->width) + tmp_addr.x = lcd->width - 1; + tmp_addr.y %= lcd->height; + + priv->addr = tmp_addr; charlcd_gotoxy(lcd); - processed = 1; break; } + } /* TODO: This indent party here got ugly, clean it! */ /* Check whether one flag was changed */ -- 2.11.0