From owner-svn-src-head@freebsd.org Mon Jan 2 18:34:56 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AE6B9C9C7C2; Mon, 2 Jan 2017 18:34:56 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-wj0-f196.google.com (mail-wj0-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F05F1314; Mon, 2 Jan 2017 18:34:56 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-wj0-f196.google.com with SMTP id j10so69487844wjb.3; Mon, 02 Jan 2017 10:34:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=EgG2VxNGI/jY1rhXvcQ3dX2izYQXXEX1TfLJWb36hVg=; b=CFdvCk7Yavwugw49GUldNUN+3RB3s3pYIzEOux5HsrRfpTpKSkCHZ6OaokFE56ejze twsJdSZr137j9yt8L+ixhjHuHJcyFOVpY4TbHpq5wPohTVs8nfvqv1RykxHAFfCuM65E xhl1/4YTPkx3MUnyYfC9rgZlCzQjtwf3EWNqdsJuztH2Tz1W51biV40QJ1qllbAZ3kDh QN0h5KFoLpNs/rk+JuD7cCj6BymZGm3DiWb5f5FaRgR6UwcESeErsUSV+wDhzgrP1Vri Jm+zy0YckJKktB0Eh4Wkg/mncM+FNiEzI8zxOqJ5EvgH0EFcyR5uuqz1PfYCUeYTXP03 vHlg== X-Gm-Message-State: AIkVDXLTCP1iTzQ6ymcnqTmg+bOQXzn561HIF779c8qFRzHctYXq9m2I2r1AZzRbXxhB9g== X-Received: by 10.194.82.8 with SMTP id e8mr49744164wjy.97.1483381727176; Mon, 02 Jan 2017 10:28:47 -0800 (PST) Received: from mail-wj0-f169.google.com (mail-wj0-f169.google.com. [209.85.210.169]) by smtp.gmail.com with ESMTPSA id cl10sm88782841wjb.4.2017.01.02.10.28.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2017 10:28:47 -0800 (PST) Received: by mail-wj0-f169.google.com with SMTP id sd9so244707330wjb.1; Mon, 02 Jan 2017 10:28:47 -0800 (PST) X-Received: by 10.195.9.102 with SMTP id dr6mr41128660wjd.209.1483381726805; Mon, 02 Jan 2017 10:28:46 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.194.29.72 with HTTP; Mon, 2 Jan 2017 10:28:46 -0800 (PST) In-Reply-To: <201701021823.v02INWXc028047@repo.freebsd.org> References: <201701021823.v02INWXc028047@repo.freebsd.org> From: Conrad Meyer Date: Mon, 2 Jan 2017 10:28:46 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r311109 - head/usr.bin/patch To: "Pedro F. Giffuni" Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jan 2017 18:34:56 -0000 IMO this patch was mostly fine, you just need to restrict line length to UINT32_MAX/2 instead of UINT_MAX (== UINT32_MAX) for 32-bit platforms. Best, Conrad On Mon, Jan 2, 2017 at 10:23 AM, Pedro F. Giffuni wrote: > Author: pfg > Date: Mon Jan 2 18:23:31 2017 > New Revision: 311109 > URL: https://svnweb.freebsd.org/changeset/base/311109 > > Log: > Revert r311106: > patch(1): extend the maximum length of a line from USHRT_MAX to UINT_MAX. > > This doesn't really work for 32 bit platforms. > > Pointed out by: kib > > Modified: > head/usr.bin/patch/patch.c > head/usr.bin/patch/pch.c > head/usr.bin/patch/pch.h > > Modified: head/usr.bin/patch/patch.c > ============================================================================== > --- head/usr.bin/patch/patch.c Mon Jan 2 18:20:22 2017 (r311108) > +++ head/usr.bin/patch/patch.c Mon Jan 2 18:23:31 2017 (r311109) > @@ -749,13 +749,15 @@ rej_line(int ch, LINENUM i) > size_t len; > const char *line = pfetch(i); > > - len = strnlen(line, UINT_MAX); > + len = strnlen(line, USHRT_MAX); > > fprintf(rejfp, "%c%s", ch, line); > - if (len == 0 || line[len-1] != '\n') > - fprintf(rejfp, "\n\\ No newline at end of line\n"); > - else if (len >= UINT_MAX) > - fprintf(rejfp, "\n\\ Line too long\n"); > + if (len == 0 || line[len-1] != '\n') { > + if (len >= USHRT_MAX) > + fprintf(rejfp, "\n\\ Line too long\n"); > + else > + fprintf(rejfp, "\n\\ No newline at end of line\n"); > + } > } > > static void > @@ -1022,7 +1024,7 @@ patch_match(LINENUM base, LINENUM offset > LINENUM pat_lines = pch_ptrn_lines() - fuzz; > const char *ilineptr; > const char *plineptr; > - u_int plinelen; > + unsigned short plinelen; > > for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) { > ilineptr = ifetch(iline, offset >= 0); > > Modified: head/usr.bin/patch/pch.c > ============================================================================== > --- head/usr.bin/patch/pch.c Mon Jan 2 18:20:22 2017 (r311108) > +++ head/usr.bin/patch/pch.c Mon Jan 2 18:23:31 2017 (r311109) > @@ -56,7 +56,7 @@ static LINENUM p_max; /* max allowed va > static LINENUM p_context = 3; /* # of context lines */ > static LINENUM p_input_line = 0; /* current line # from patch file */ > static char **p_line = NULL;/* the text of the hunk */ > -static u_int *p_len = NULL; /* length of each line */ > +static unsigned short *p_len = NULL; /* length of each line */ > static char *p_char = NULL; /* +, -, and ! */ > static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ > static int p_indent; /* indent to patch */ > @@ -136,7 +136,7 @@ set_hunkmax(void) > if (p_line == NULL) > p_line = malloc(hunkmax * sizeof(char *)); > if (p_len == NULL) > - p_len = malloc(hunkmax * sizeof(u_int)); > + p_len = malloc(hunkmax * sizeof(unsigned short)); > if (p_char == NULL) > p_char = malloc(hunkmax * sizeof(char)); > } > @@ -153,7 +153,7 @@ grow_hunkmax(void) > fatal("Internal memory allocation error\n"); > > p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); > - p_len = reallocf(p_len, new_hunkmax * sizeof(u_int)); > + p_len = reallocf(p_len, new_hunkmax * sizeof(unsigned short)); > p_char = reallocf(p_char, new_hunkmax * sizeof(char)); > > if (p_line != NULL && p_len != NULL && p_char != NULL) { > @@ -1210,7 +1210,7 @@ bool > pch_swap(void) > { > char **tp_line; /* the text of the hunk */ > - u_int *tp_len; /* length of each line */ > + unsigned short *tp_len;/* length of each line */ > char *tp_char; /* +, -, and ! */ > LINENUM i; > LINENUM n; > @@ -1367,7 +1367,7 @@ pch_context(void) > /* > * Return the length of a particular patch line. > */ > -u_int > +unsigned short > pch_line_len(LINENUM line) > { > return p_len[line]; > > Modified: head/usr.bin/patch/pch.h > ============================================================================== > --- head/usr.bin/patch/pch.h Mon Jan 2 18:20:22 2017 (r311108) > +++ head/usr.bin/patch/pch.h Mon Jan 2 18:23:31 2017 (r311109) > @@ -44,7 +44,7 @@ bool there_is_another_patch(void); > bool another_hunk(void); > bool pch_swap(void); > char *pfetch(LINENUM); > -u_int pch_line_len(LINENUM); > +unsigned short pch_line_len(LINENUM); > LINENUM pch_first(void); > LINENUM pch_ptrn_lines(void); > LINENUM pch_newfirst(void); >