Permalink
Browse files

Check umove() return code

* bjm.c (sys_query_module): Print input parameters when entering
syscall.  Fix handling of syscall error.  Handle unlikely umove()
failures.
* ipc.c (tprint_msgrcv): New function.  Move part of msgrcv parser code
here, add check umove() return code.
(sys_msgsnd): Print msqid parameter as int instead of long.
(sys_msgrcv): Likewise.  Use tprint_msgrcv().
* process.c (print_affinitylist): Check umove() return code.
* sock.c (sock_ioctl): Handle unlikely umove() failure in the
SIOCGIFCONF parser.
  • Loading branch information...
1 parent f0df31e commit 62e0596dbda6831f7f7a976c183373d5ff7a7584 @ldv-alt ldv-alt committed Nov 3, 2009
Showing with 99 additions and 66 deletions.
  1. +43 −36 bjm.c
  2. +26 −20 ipc.c
  3. +24 −8 process.c
  4. +6 −2 sock.c
View
79 bjm.c
@@ -98,75 +98,82 @@ static const struct xlat modflags[] = {
};
int
-sys_query_module(tcp)
-struct tcb *tcp;
+sys_query_module(struct tcb *tcp)
{
-
- if (exiting(tcp)) {
+ if (entering(tcp)) {
printstr(tcp, tcp->u_arg[0], -1);
tprintf(", ");
printxval(which, tcp->u_arg[1], "QM_???");
tprintf(", ");
- if (!verbose(tcp)) {
- tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
- } else if (tcp->u_rval!=0) {
- size_t ret;
- umove(tcp, tcp->u_arg[4], &ret);
- tprintf("%#lx, %lu, %Zu", tcp->u_arg[2], tcp->u_arg[3], ret);
+ } else {
+ size_t ret;
+
+ if (!verbose(tcp) || syserror(tcp) ||
+ umove(tcp, tcp->u_arg[4], &ret) < 0) {
+ tprintf("%#lx, %lu, %#lx", tcp->u_arg[2],
+ tcp->u_arg[3], tcp->u_arg[4]);
} else if (tcp->u_arg[1]==QM_INFO) {
struct module_info mi;
- size_t ret;
- umove(tcp, tcp->u_arg[2], &mi);
- tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size);
- printflags(modflags, mi.flags, "MOD_???");
- tprintf(", usecount=%lu}", mi.usecount);
- umove(tcp, tcp->u_arg[4], &ret);
- tprintf(", %Zu", ret);
+ if (umove(tcp, tcp->u_arg[2], &mi) < 0) {
+ tprintf("%#lx, ", tcp->u_arg[2]);
+ } else {
+ tprintf("{address=%#lx, size=%lu, flags=",
+ mi.addr, mi.size);
+ printflags(modflags, mi.flags, "MOD_???");
+ tprintf(", usecount=%lu}, ", mi.usecount);
+ }
+ tprintf("%Zu", ret);
} else if ((tcp->u_arg[1]==QM_MODULES) ||
(tcp->u_arg[1]==QM_DEPS) ||
(tcp->u_arg[1]==QM_REFS)) {
- size_t ret;
-
- umove(tcp, tcp->u_arg[4], &ret);
tprintf("{");
if (!abbrev(tcp)) {
- char* data = (char*)malloc(tcp->u_arg[3]);
+ char* data = malloc(tcp->u_arg[3]);
char* mod = data;
size_t idx;
- if (data==NULL) {
+ if (!data) {
fprintf(stderr, "out of memory\n");
tprintf(" /* %Zu entries */ ", ret);
} else {
- umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
- for (idx=0; idx<ret; idx++) {
- if (idx!=0)
- tprintf(",");
- tprintf("%s", mod);
- mod+=strlen(mod)+1;
+ if (umoven(tcp, tcp->u_arg[2],
+ tcp->u_arg[3], data) < 0) {
+ tprintf(" /* %Zu entries */ ", ret);
+ } else {
+ for (idx=0; idx<ret; idx++) {
+ tprintf("%s%s",
+ (idx ? ", " : ""),
+ mod);
+ mod += strlen(mod)+1;
+ }
}
free(data);
}
} else
tprintf(" /* %Zu entries */ ", ret);
tprintf("}, %Zu", ret);
} else if (tcp->u_arg[1]==QM_SYMBOLS) {
- size_t ret;
- umove(tcp, tcp->u_arg[4], &ret);
tprintf("{");
if (!abbrev(tcp)) {
- char* data = (char *)malloc(tcp->u_arg[3]);
+ char* data = malloc(tcp->u_arg[3]);
struct module_symbol* sym = (struct module_symbol*)data;
size_t idx;
- if (data==NULL) {
+ if (!data) {
fprintf(stderr, "out of memory\n");
tprintf(" /* %Zu entries */ ", ret);
} else {
- umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
- for (idx=0; idx<ret; idx++) {
- tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value);
- sym++;
+ if (umoven(tcp, tcp->u_arg[2],
+ tcp->u_arg[3], data) < 0) {
+ tprintf(" /* %Zu entries */ ", ret);
+ } else {
+ for (idx=0; idx<ret; idx++) {
+ tprintf("%s{name=%s, value=%lu}",
+ (idx ? " " : ""),
+ data+(long)sym->name,
+ sym->value);
+ sym++;
+ }
}
free(data);
}
View
46 ipc.c
@@ -230,7 +230,7 @@ tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count)
int sys_msgsnd(struct tcb *tcp)
{
if (entering(tcp)) {
- tprintf("%lu, ", tcp->u_arg[0]);
+ tprintf("%d, ", (int) tcp->u_arg[0]);
if (indirect_ipccall(tcp)) {
tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1]);
} else {
@@ -240,37 +240,43 @@ int sys_msgsnd(struct tcb *tcp)
return 0;
}
-int sys_msgrcv(tcp)
-struct tcb *tcp;
+static void
+tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp)
{
long mtype;
+ if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) {
+ tprintf("%#lx", addr);
+ } else {
+ tprintf("{%lu, ", mtype);
+ printstr(tcp, addr + sizeof(mtype), count);
+ tprintf("}");
+ }
+ tprintf(", %lu, %ld, ", count, msgtyp);
+}
+
+int sys_msgrcv(struct tcb *tcp)
+{
if (entering(tcp)) {
- tprintf("%lu, ", tcp->u_arg[0]);
+ tprintf("%d, ", (int) tcp->u_arg[0]);
} else {
- tprintf("%lu", tcp->u_arg[0]);
if (indirect_ipccall(tcp)) {
struct ipc_wrapper {
struct msgbuf *msgp;
long msgtyp;
} tmp;
- umove(tcp, tcp->u_arg[3], &tmp);
- umove(tcp, (long) tmp.msgp, &mtype);
- tprintf(", {%lu, ", mtype);
- printstr(tcp, (long) (tmp.msgp) + sizeof(long),
- tcp->u_arg[1]);
- tprintf("}, %lu", tcp->u_arg[1]);
- tprintf(", %ld", tmp.msgtyp);
- tprintf(", ");
+
+ if (umove(tcp, tcp->u_arg[3], &tmp) < 0) {
+ tprintf("%#lx, %lu, ",
+ tcp->u_arg[3], tcp->u_arg[1]);
+ } else {
+ tprint_msgrcv(tcp, (long) tmp.msgp,
+ tcp->u_arg[1], tmp.msgtyp);
+ }
printflags(msg_flags, tcp->u_arg[2], "MSG_???");
} else {
- umove(tcp, tcp->u_arg[1], &mtype);
- tprintf("{%lu, ", mtype);
- printstr(tcp, tcp->u_arg[1] + sizeof(long),
- tcp->u_arg[2]);
- tprintf("}, %lu", tcp->u_arg[2]);
- tprintf(", %ld", tcp->u_arg[3]);
- tprintf(", ");
+ tprint_msgrcv(tcp, tcp->u_arg[1],
+ tcp->u_arg[2], tcp->u_arg[3]);
printflags(msg_flags, tcp->u_arg[4], "MSG_???");
}
}
View
32 process.c
@@ -3546,16 +3546,32 @@ static void
print_affinitylist(struct tcb *tcp, long list, unsigned int len)
{
int first = 1;
- tprintf(" {");
- while (len >= sizeof (unsigned long)) {
- unsigned long w;
- umove(tcp, list, &w);
- tprintf("%s %lx", first ? "" : ",", w);
+ unsigned long w, min_len;
+
+ if (abbrev(tcp) && len / sizeof(w) > max_strlen)
+ min_len = len - max_strlen * sizeof(w);
+ else
+ min_len = 0;
+ for (; len >= sizeof(w) && len > min_len;
+ len -= sizeof(w), list += sizeof(w)) {
+ if (umove(tcp, list, &w) < 0)
+ break;
+ if (first)
+ tprintf("{");
+ else
+ tprintf(", ");
first = 0;
- len -= sizeof (unsigned long);
- list += sizeof(unsigned long);
+ tprintf("%lx", w);
+ }
+ if (len) {
+ if (first)
+ tprintf("%#lx", list);
+ else
+ tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
+ "???" : "..."));
+ } else {
+ tprintf(first ? "{}" : "}");
}
- tprintf(" }");
}
int
View
8 sock.c
@@ -258,8 +258,12 @@ sock_ioctl(struct tcb *tcp, long code, long arg)
int i;
unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
struct ifreq ifra[nifra];
- umoven(tcp, (unsigned long) ifc.ifc_buf, sizeof(ifra),
- (char *) ifra);
+
+ if (umoven(tcp, (unsigned long) ifc.ifc_buf,
+ sizeof(ifra), (char *) ifra) < 0) {
+ tprintf("%lx}", (unsigned long) ifc.ifc_buf);
+ return 1;
+ }
tprintf("{");
for (i = 0; i < nifra; ++i ) {
if (i > 0)

0 comments on commit 62e0596

Please sign in to comment.