mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-04 09:09:56 +00:00
Support readlink(2) better. Readlink does not nul terminate the
result buffer, so we need to format it ourselves. The problem is that the length is stored as the return value from readlink, so we need to pass the return value from our syscall into print_arg. Motivated by: truss garbage on my screen from reading /etc/malloc.conf.
This commit is contained in:
parent
969860f3ed
commit
2bae4eb308
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=132308
@ -238,7 +238,7 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -342,7 +342,7 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -327,7 +327,7 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -321,7 +321,7 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -312,7 +312,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -321,7 +321,7 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -312,7 +312,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -308,7 +308,7 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
i < (fsc.nargs - 1) ? "," : "");
|
||||
#endif
|
||||
if (sc && !(sc->args[i].type & OUT)) {
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
@ -343,7 +343,7 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
if (errorp)
|
||||
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
|
||||
else
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args);
|
||||
temp = print_arg(Procfd, &sc->args[i], fsc.args, retval);
|
||||
fsc.s_args[i] = temp;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
enum Argtype { None = 1, Hex, Octal, Int, String, Ptr, Stat, Ioctl, Quad,
|
||||
Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd,
|
||||
Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence };
|
||||
Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres };
|
||||
|
||||
#define ARG_MASK 0xff
|
||||
#define OUT 0x100
|
||||
@ -53,7 +53,7 @@ struct syscall {
|
||||
|
||||
struct syscall *get_syscall(const char*);
|
||||
char *get_string(int, void*, int);
|
||||
char *print_arg(int, struct syscall_args *, unsigned long*);
|
||||
char *print_arg(int, struct syscall_args *, unsigned long*, long);
|
||||
void print_syscall(struct trussinfo *, const char *, int, char **);
|
||||
void print_syscall_ret(struct trussinfo *, const char *, int, char **, int,
|
||||
long);
|
||||
|
@ -71,7 +71,7 @@ struct syscall syscalls[] = {
|
||||
{ "fcntl", 1, 3,
|
||||
{ { Int, 0 } , { Fcntl, 1 }, { Hex, 2 }}},
|
||||
{ "readlink", 1, 3,
|
||||
{ { String, 0 } , { String | OUT, 1 }, { Int, 2 }}},
|
||||
{ { String, 0 } , { Readlinkres | OUT, 1 }, { Int, 2 }}},
|
||||
{ "lseek", 2, 3,
|
||||
{ { Int, 0 }, {Quad, 2 }, { Whence, 4 }}},
|
||||
{ "linux_lseek", 2, 3,
|
||||
@ -271,7 +271,7 @@ remove_trailing_or(char *str)
|
||||
*/
|
||||
|
||||
char *
|
||||
print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
|
||||
print_arg(int fd, struct syscall_args *sc, unsigned long *args, long retval) {
|
||||
char *tmp = NULL;
|
||||
switch (sc->type & ARG_MASK) {
|
||||
case Hex:
|
||||
@ -338,6 +338,18 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
|
||||
case Ptr:
|
||||
asprintf(&tmp, "0x%lx", args[sc->offset]);
|
||||
break;
|
||||
case Readlinkres:
|
||||
{
|
||||
char *tmp2;
|
||||
if (retval == -1) {
|
||||
tmp = strdup("");
|
||||
break;
|
||||
}
|
||||
tmp2 = get_string(fd, (void*)args[sc->offset], retval);
|
||||
asprintf(&tmp, "\"%s\"", tmp2);
|
||||
free(tmp2);
|
||||
}
|
||||
break;
|
||||
case Ioctl:
|
||||
{
|
||||
const char *temp = ioctlname(args[sc->offset]);
|
||||
|
Loading…
Reference in New Issue
Block a user