From owner-svn-src-head@freebsd.org Sat Mar 23 02:17:08 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B8932155A0C1; Sat, 23 Mar 2019 02:17:08 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5C34A7022A; Sat, 23 Mar 2019 02:17:08 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1D50E1715; Sat, 23 Mar 2019 02:17:08 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2N2H7Nq031714; Sat, 23 Mar 2019 02:17:07 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2N2H726031713; Sat, 23 Mar 2019 02:17:07 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201903230217.x2N2H726031713@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sat, 23 Mar 2019 02:17:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345431 - head/contrib/elftoolchain/strings X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/contrib/elftoolchain/strings X-SVN-Commit-Revision: 345431 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5C34A7022A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.975,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Sat, 23 Mar 2019 02:17:09 -0000 Author: oshogbo Date: Sat Mar 23 02:17:07 2019 New Revision: 345431 URL: https://svnweb.freebsd.org/changeset/base/345431 Log: strings: return an error code and the char value separately If we returning 32 bits value it's hard to distinguish if the returned value is a valid one or if its an error (in case of EOF). For that reason separate exit code of the function from the returned character. Reported by: cem, se Modified: head/contrib/elftoolchain/strings/strings.c Modified: head/contrib/elftoolchain/strings/strings.c ============================================================================== --- head/contrib/elftoolchain/strings/strings.c Sat Mar 23 01:07:51 2019 (r345430) +++ head/contrib/elftoolchain/strings/strings.c Sat Mar 23 02:17:07 2019 (r345431) @@ -84,7 +84,7 @@ static struct option strings_longopts[] = { { NULL, 0, NULL, 0 } }; -long getcharacter(FILE *); +int getcharacter(FILE *, long *); int handle_file(const char *); int handle_elf(const char *, FILE *); int handle_binary(const char *, FILE *, size_t); @@ -291,42 +291,43 @@ handle_elf(const char *name, FILE *pfile) * Retrieves a character from input stream based on the encoding * type requested. */ -long -getcharacter(FILE *pfile) +int +getcharacter(FILE *pfile, long *rt) { - long rt; int i, c; char buf[4]; for(i = 0; i < encoding_size; i++) { c = getc(pfile); if (c == EOF) - return (EOF); + return (-1); buf[i] = c; } - rt = EOF; switch (encoding) { case ENCODING_7BIT: case ENCODING_8BIT: - rt = buf[0]; + *rt = buf[0]; break; case ENCODING_16BIT_BIG: - rt = (buf[0] << 8) | buf[1]; + *rt = (buf[0] << 8) | buf[1]; break; case ENCODING_16BIT_LITTLE: - rt = buf[0] | (buf[1] << 8); - break; + *rt = buf[0] | (buf[1] << 8); + break; case ENCODING_32BIT_BIG: - rt = ((long) buf[0] << 24) | ((long) buf[1] << 16) | + *rt = ((long) buf[0] << 24) | ((long) buf[1] << 16) | ((long) buf[2] << 8) | buf[3]; break; case ENCODING_32BIT_LITTLE: - rt = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) | + *rt = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) | ((long) buf[3] << 24); break; + default: + return (-1); } - return (rt); + + return (0); } /* @@ -357,8 +358,7 @@ find_strings(const char *name, FILE *pfile, off_t offs start_off = cur_off; memset(obuf, 0, min_len + 1); for(i = 0; i < min_len; i++) { - c = getcharacter(pfile); - if (c == EOF) + if (getcharacter(pfile, &c) < 0) goto _exit1; if (PRINTABLE(c)) { obuf[i] = c; @@ -400,15 +400,16 @@ find_strings(const char *name, FILE *pfile, off_t offs if ((offset + size) && (cur_off >= offset + size)) break; - c = getcharacter(pfile); - cur_off += encoding_size; - if (!PRINTABLE(c) || c == EOF) + if (getcharacter(pfile, &c) < 0) break; + cur_off += encoding_size; if (encoding == ENCODING_8BIT && (uint8_t)c > 127) { putchar(c); continue; } + if (!PRINTABLE(c)) + break; putchar(c); } putchar('\n');