Do not ignore any possible errors that fseeko() may have. The fact
is that fseeko() fails in very predictable and frequent ways on ia64. This is because the offset is actually an address in the process' address space, which on ia64 can be larger than long (for lseek) or off_t (for fseeko). The crux is the signedness. The register stack and memory stack are in region 4 on ia64. This means that the sign bit is 1. The large positive virtual address is wrongly interpreted as a negative file offset. There's no quick fix. Even if you get around the API by using a SEEK_SET up to LONG_MAX and follow it up with a SEEK_CUR for the remainder, the kernel simply cannot deal with it. and the second seek will just fail. Therefore, this change does not actually fix the root cause. It just makes sure we're not spitting out all kinds of garbage or that the get_struct() function in particular does not cause truss(1) to exit. This, I might add, invariably happened way too soon for truss(1) to be of any use on ia64...
This commit is contained in:
parent
b70d5d25f2
commit
4e92419dcd
@ -171,12 +171,14 @@ get_struct(int procfd, void *offset, void *buf, int len) {
|
||||
err(1, "dup");
|
||||
if ((p = fdopen(fd, "r")) == NULL)
|
||||
err(1, "fdopen");
|
||||
fseeko(p, (uintptr_t)offset, SEEK_SET);
|
||||
for (pos = (char *)buf; len--; pos++) {
|
||||
if ((c = fgetc(p)) == EOF)
|
||||
return -1;
|
||||
*pos = c;
|
||||
}
|
||||
if (fseeko(p, (uintptr_t)offset, SEEK_SET) == 0) {
|
||||
for (pos = (char *)buf; len--; pos++) {
|
||||
if ((c = fgetc(p)) == EOF)
|
||||
return (-1);
|
||||
*pos = c;
|
||||
}
|
||||
} else
|
||||
bzero(buf, len);
|
||||
fclose(p);
|
||||
return 0;
|
||||
}
|
||||
@ -201,27 +203,27 @@ get_string(int procfd, void *offset, int max) {
|
||||
buf = malloc( size = (max ? max : 64 ) );
|
||||
len = 0;
|
||||
buf[0] = 0;
|
||||
fseeko(p, (uintptr_t)offset, SEEK_SET);
|
||||
while ((c = fgetc(p)) != EOF) {
|
||||
buf[len++] = c;
|
||||
if (c == 0 || len == max) {
|
||||
buf[len] = 0;
|
||||
break;
|
||||
}
|
||||
if (len == size) {
|
||||
char *tmp;
|
||||
tmp = realloc(buf, size+64);
|
||||
if (tmp == NULL) {
|
||||
if (fseeko(p, (uintptr_t)offset, SEEK_SET) == 0) {
|
||||
while ((c = fgetc(p)) != EOF) {
|
||||
buf[len++] = c;
|
||||
if (c == 0 || len == max) {
|
||||
buf[len] = 0;
|
||||
fclose(p);
|
||||
return buf;
|
||||
break;
|
||||
}
|
||||
if (len == size) {
|
||||
char *tmp;
|
||||
tmp = realloc(buf, size+64);
|
||||
if (tmp == NULL) {
|
||||
buf[len] = 0;
|
||||
break;
|
||||
}
|
||||
size += 64;
|
||||
buf = tmp;
|
||||
}
|
||||
size += 64;
|
||||
buf = tmp;
|
||||
}
|
||||
}
|
||||
fclose(p);
|
||||
return buf;
|
||||
return (buf);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user