[PATCH 2/2] Change type of the format specifier from "%lu" to "%d" for IPC ID

2016-09-07 Thread Eugene Syromyatnikov
* ipc_msgctl.c (SYS_FUNC(msgctl)): Convert format specifier of the first
  argument from "%lu" to "%d", cast argument to int.
* ipc_sem.c (SYS_FUNC(semop)): Likewise.
  (SYS_FUNC(semtimedop)): Likewise.
  (SYS_FUNC(semget)): Likewise.
* ipc_shm.c (SYS_FUNC(shmat)): Likewise.
* ipc_shmctl.c (SYS_FUNC(shmctl)): Likewise.
---
 ipc_msgctl.c |2 +-
 ipc_sem.c|8 
 ipc_shm.c|2 +-
 ipc_shmctl.c |2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/ipc_msgctl.c b/ipc_msgctl.c
index 9be35ce..a7352cb 100644
--- a/ipc_msgctl.c
+++ b/ipc_msgctl.c
@@ -97,7 +97,7 @@ print_msqid_ds(struct tcb *tcp, const long addr, int cmd)
 SYS_FUNC(msgctl)
 {
if (entering(tcp)) {
-   tprintf("%lu, ", tcp->u_arg[0]);
+   tprintf("%d, ", (int) tcp->u_arg[0]);
PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
tprints(", ");
} else {
diff --git a/ipc_sem.c b/ipc_sem.c
index e6172ee..81a2ff7 100644
--- a/ipc_sem.c
+++ b/ipc_sem.c
@@ -71,7 +71,7 @@ tprint_sembuf_array(struct tcb *tcp, const long addr, const 
unsigned long count)
 
 SYS_FUNC(semop)
 {
-   tprintf("%lu, ", tcp->u_arg[0]);
+   tprintf("%d, ", (int)tcp->u_arg[0]);
if (indirect_ipccall(tcp)) {
tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
} else {
@@ -82,7 +82,7 @@ SYS_FUNC(semop)
 
 SYS_FUNC(semtimedop)
 {
-   tprintf("%lu, ", tcp->u_arg[0]);
+   tprintf("%d, ", (int) tcp->u_arg[0]);
if (indirect_ipccall(tcp)) {
tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
tprints(", ");
@@ -105,7 +105,7 @@ SYS_FUNC(semget)
tprintf("%#lx", tcp->u_arg[0]);
else
tprints("IPC_PRIVATE");
-   tprintf(", %lu, ", tcp->u_arg[1]);
+   tprintf(", %d, ", (int) tcp->u_arg[1]);
if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
tprints("|");
print_numeric_umode_t(tcp->u_arg[2] & 0777);
@@ -114,7 +114,7 @@ SYS_FUNC(semget)
 
 SYS_FUNC(semctl)
 {
-   tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
+   tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
tprints(", ");
if (indirect_ipccall(tcp)
diff --git a/ipc_shm.c b/ipc_shm.c
index e8a8206..072c5e1 100644
--- a/ipc_shm.c
+++ b/ipc_shm.c
@@ -57,7 +57,7 @@ SYS_FUNC(shmget)
 SYS_FUNC(shmat)
 {
if (entering(tcp)) {
-   tprintf("%lu, ", tcp->u_arg[0]);
+   tprintf("%d, ", (int) tcp->u_arg[0]);
if (indirect_ipccall(tcp)) {
printaddr(tcp->u_arg[3]);
tprints(", ");
diff --git a/ipc_shmctl.c b/ipc_shmctl.c
index 7ea3672..12bb806 100644
--- a/ipc_shmctl.c
+++ b/ipc_shmctl.c
@@ -97,7 +97,7 @@ print_shmid_ds(struct tcb *tcp, const long addr, int cmd)
 SYS_FUNC(shmctl)
 {
if (entering(tcp)) {
-   tprintf("%lu, ", tcp->u_arg[0]);
+   tprintf("%d, ", (int) tcp->u_arg[0]);
PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
tprints(", ");
} else {
-- 
1.7.10.4


--
___
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel


[PATCH 1/2] tests: Additional IPC checks

2016-09-07 Thread Eugene Syromyatnikov
* tests/ipc_msg.c: Additional msgget (parameter format), msgctl
  (parameter format, decoding of struct msqid_ds in IPC_SET/IPC_STAT
  commands) checks.
* tests/ipc_sem.c: Additional semget, semctl checks.
* tests/ipc_shm.c: Additional shmctl checks.
* tests/semop.c: Additional semop checks. Added checks for semtimedop.
* tests/semop.test: Add explicit -e parameter in order to trace both
  semop and semtimedop.
* tests/shmxt.c: Additional shmat/shmdt tests.
---
 tests/ipc_msg.c  |   51 +-
 tests/ipc_sem.c  |   27 +++
 tests/ipc_shm.c  |   23 +--
 tests/semop.c|   65 ++
 tests/semop.test |2 +-
 tests/shmxt.c|   11 +
 6 files changed, 170 insertions(+), 9 deletions(-)

diff --git a/tests/ipc_msg.c b/tests/ipc_msg.c
index 2fd7d4f..5bd6116 100644
--- a/tests/ipc_msg.c
+++ b/tests/ipc_msg.c
@@ -27,10 +27,15 @@
  */
 
 #include "tests.h"
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+
+#include "xlat.h"
+#include "xlat/resource_flags.h"
 
 static int id = -1;
 
@@ -48,18 +53,43 @@ main(void)
int rc;
struct msqid_ds ds;
 
+   static const key_t bogus_key = (key_t)0xeca86420fdb97531ULL;
+   static const int bogus_msgid = 0xfdb97531;
+   static const int bogus_cmd = 0xdeadbeef;
+   static void * const bogus_addr = (void *) -1L;
+   static const int bogus_flags = 0xface1e55 & ~IPC_CREAT;
+
+   assert(msgget(bogus_key, bogus_flags) == -1);
+   printf("msgget\\(%#lx, %s%s%s%#x\\|%#04o\\) += %s\n",
+   (unsigned long)((sizeof(key_t) == sizeof(int)) ?
+   (unsigned)bogus_key : (unsigned long)bogus_key),
+   IPC_CREAT & bogus_flags ? "IPC_CREAT\\|" : "",
+   IPC_EXCL & bogus_flags ? "IPC_EXCL\\|" : "",
+   IPC_NOWAIT & bogus_flags ? "IPC_NOWAIT\\|" : "",
+   bogus_flags & ~(0777 | IPC_CREAT | IPC_EXCL | IPC_NOWAIT),
+   bogus_flags & 0777,
+   sprintrc_grep(-1));
+
id = msgget(IPC_PRIVATE, 0600);
if (id < 0)
perror_msg_and_skip("msgget");
printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id);
atexit(cleanup);
 
+   assert(msgctl(bogus_msgid, bogus_cmd, NULL) == -1);
+   printf("msgctl\\(%d, (IPC_64\\|)?%#x /\\* MSG_\\?\\?\\? \\*/, NULL\\) "
+   "+= %s\n", bogus_msgid, bogus_cmd, sprintrc_grep(-1));
+
+   assert(msgctl(bogus_msgid, IPC_SET, bogus_addr) == -1);
+   printf("msgctl\\(%d, (IPC_64\\|)?IPC_SET, %p\\) += %s\n",
+   bogus_msgid, bogus_addr, sprintrc_grep(-1));
+
if (msgctl(id, IPC_STAT, ))
perror_msg_and_skip("msgctl IPC_STAT");
-   printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{msg_perm=\\{uid=%u, 
gid=%u, "
-   "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, msg_stime=%u, 
msg_rtime=%u, "
-   "msg_ctime=%u, msg_qnum=%u, msg_qbytes=%u, msg_lspid=%u, "
-   "msg_lrpid=%u\\}\\) += 0\n",
+   printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{msg_perm=\\{uid=%u, "
+   "gid=%u, mode=%#o, key=%u, cuid=%u, cgid=%u\\}, msg_stime=%u, "
+   "msg_rtime=%u, msg_ctime=%u, msg_qnum=%u, msg_qbytes=%u, "
+   "msg_lspid=%u, msg_lrpid=%u\\}\\) += 0\n",
id, (unsigned) ds.msg_perm.uid, (unsigned) ds.msg_perm.gid,
(unsigned) ds.msg_perm.mode, (unsigned) ds.msg_perm.__key,
(unsigned) ds.msg_perm.cuid, (unsigned) ds.msg_perm.cgid,
@@ -68,6 +98,13 @@ main(void)
(unsigned) ds.msg_qbytes, (unsigned) ds.msg_lspid,
(unsigned) ds.msg_lrpid);
 
+   if (msgctl(id, IPC_SET, ))
+   perror_msg_and_skip("msgctl IPC_SET");
+   printf("msgctl\\(%d, (IPC_64\\|)?IPC_SET, \\{msg_perm=\\{uid=%u, "
+   "gid=%u, mode=%#o\\}, ...\\}\\) += 0\n",
+   id, (unsigned) ds.msg_perm.uid, (unsigned) ds.msg_perm.gid,
+   (unsigned) ds.msg_perm.mode);
+
int max = msgctl(0, MSG_INFO, );
if (max < 0)
perror_msg_and_skip("msgctl MSG_INFO");
@@ -81,9 +118,11 @@ main(void)
 */
if (-1 != rc || EINVAL != errno)
perror_msg_and_skip("msgctl MSG_STAT");
-   printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL 
\\(%m\\)\n", id, );
+   printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += "
+   "-1 EINVAL \\(%m\\)\n", id, );
} else {
-   printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, 
, id);
+   printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n",
+   id, , id);
}
 
return 0;
diff --git a/tests/ipc_sem.c b/tests/ipc_sem.c
index afe74d2..09f191d 100644
--- a/tests/ipc_sem.c
+++ b/tests/ipc_sem.c
@@ -27,11 +27,15 @@
  */
 
 #include "tests.h"

[PATCH 0/2] Additional checks for IPC tests

2016-09-07 Thread Eugene Syromyatnikov
Hello.

I've noticed that IPC tests do not check first parameter (IPC ID) enough
which allowed incorrect format specifier usage. These patches augment
tests with regard to aforementioned issue and correct illicit behaviour.

Eugene Syromyatnikov (2):
  tests: Additional IPC checks
  Change type of the format specifier from "%lu" to "%d" for IPC ID

 ipc_msgctl.c |2 +-
 ipc_sem.c|8 +++
 ipc_shm.c|2 +-
 ipc_shmctl.c |2 +-
 tests/ipc_msg.c  |   51 +-
 tests/ipc_sem.c  |   27 +++
 tests/ipc_shm.c  |   23 +--
 tests/semop.c|   65 ++
 tests/semop.test |2 +-
 tests/shmxt.c|   11 +
 10 files changed, 177 insertions(+), 16 deletions(-)

-- 
1.7.10.4


--
___
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel