version 1.72, 2014/04/22 21:24:20 |
version 1.73, 2014/05/06 23:17:13 |
|
|
struct stat sb; |
struct stat sb; |
ssize_t x, space; |
ssize_t x, space; |
int fd; |
int fd; |
|
const unsigned long long maxmsgsize = 1UL << 30; |
|
|
fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0); |
fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0); |
if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) { |
if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) { |
if (sb.st_size > (1UL << 30)) |
if (sb.st_size > maxmsgsize) |
errx(1, "msg too large in %s", filename); |
errx(1, "msg too large in %s", filename); |
space = sb.st_size + 1; |
space = sb.st_size + 1; |
} else { |
} else { |
|
|
msg = xmalloc(space + 1); |
msg = xmalloc(space + 1); |
while (1) { |
while (1) { |
if (space == 0) { |
if (space == 0) { |
if (msglen * 2 > (1UL << 30)) |
if (msglen * 2 > maxmsgsize) |
errx(1, "msg too large in %s", filename); |
errx(1, "msg too large in %s", filename); |
space = msglen; |
space = msglen; |
if (!(msg = realloc(msg, msglen + space + 1))) |
if (!(msg = realloc(msg, msglen + space + 1))) |