Gentoo Archives: gentoo-commits

From: "Michael Haubenwallner (haubi)" <haubi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-alt r1671 - trunk/aix-miscutils/ldd
Date: Fri, 26 Feb 2010 12:46:10
Message-Id: E1Nkza4-0004rf-HK@stork.gentoo.org
1 Author: haubi
2 Date: 2010-02-26 12:46:08 +0000 (Fri, 26 Feb 2010)
3 New Revision: 1671
4
5 Modified:
6 trunk/aix-miscutils/ldd/ObjectReader.cc
7 Log:
8 fixed off-by-one bug using fgets reading very long lines (runpath)
9
10 Modified: trunk/aix-miscutils/ldd/ObjectReader.cc
11 ===================================================================
12 --- trunk/aix-miscutils/ldd/ObjectReader.cc 2010-02-26 12:45:22 UTC (rev 1670)
13 +++ trunk/aix-miscutils/ldd/ObjectReader.cc 2010-02-26 12:46:08 UTC (rev 1671)
14 @@ -21,7 +21,11 @@
15 line = "";
16
17 do {
18 - linebuf[sizeof(linebuf)-1] = '\0';
19 + /* fgets always stores '\0' into the last byte read.
20 + * If the byte before the last possible one is either
21 + * unchanged or newline, we've read a whole line.
22 + */
23 + linebuf[sizeof(linebuf)-2] = '\0';
24 char *read = fgets(linebuf, sizeof(linebuf), file);
25 if (read == NULL) {
26 if (feof(file)) {
27 @@ -30,7 +34,7 @@
28 throw std::runtime_error(strerror(errno));
29 }
30 line += read;
31 - } while(linebuf[sizeof(linebuf)-1] != '\0');
32 + } while(linebuf[sizeof(linebuf)-2] != '\0' && linebuf[sizeof(linebuf)-2] != '\n');
33
34 while(line.length() > 0
35 && (line[line.length()-1] == '\n' || line[line.length()-1] == '\r')