[PATCH 1/2] tests: Additional IPC checks
Eugene Syromyatnikov
evgsyr at gmail.com
Wed Sep 7 12:41:01 UTC 2016
* 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 <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/msg.h>
+#include <sys/types.h>
+
+#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, &ds))
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, &ds))
+ 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, &ds);
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, &ds);
+ printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += "
+ "-1 EINVAL \\(%m\\)\n", id, &ds);
} else {
- printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id);
+ printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n",
+ id, &ds, 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"
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sem.h>
+#include "xlat.h"
+#include "xlat/resource_flags.h"
+
union semun {
int val; /* Value for SETVAL */
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
@@ -53,17 +57,40 @@ cleanup(void)
int
main(void)
{
+ static const key_t bogus_key = (key_t)0xeca86420fdb97531ULL;
+ static const int bogus_size = 0xdec0ded1;
+ static const int bogus_flags = 0xface1e55;
+
int rc;
union semun un;
struct semid_ds ds;
struct seminfo info;
+ assert(semget(bogus_key, bogus_size, bogus_flags) == -1);
+ printf("semget\\(%#lx, %d, %s%s%s%#x\\|%#04o\\) += %s\n",
+ (unsigned long)((sizeof(key_t) == sizeof(int)) ?
+ (unsigned)bogus_key : (unsigned long)bogus_key),
+ bogus_size,
+ 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 = semget(IPC_PRIVATE, 1, 0600);
if (id < 0)
perror_msg_and_skip("semget");
printf("semget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
atexit(cleanup);
+ assert(semctl(0xfdb97531, 0xeca86420, 0xdeadbeef,
+ (unsigned long) 0xbadc0dedfacef00dULL) == -1);
+ printf("semctl\\(%d, %d, (IPC_64\\|)?%#x /\\* SEM_\\?\\?\\? \\*/, "
+ "\\[?%#lx\\]?\\) += %s\n",
+ 0xfdb97531, 0xeca86420, 0xdeadbeef,
+ (unsigned long) 0xbadc0dedfacef00dULL, sprintrc_grep(-1));
+
un.buf = &ds;
if (semctl(id, 0, IPC_STAT, un))
perror_msg_and_skip("semctl IPC_STAT");
diff --git a/tests/ipc_shm.c b/tests/ipc_shm.c
index 80a8f0f..c2c1b26 100644
--- a/tests/ipc_shm.c
+++ b/tests/ipc_shm.c
@@ -49,8 +49,11 @@ cleanup(void)
int
main(void)
{
- static const key_t bogus_key = (key_t)0xeca86420fdb97531LLU;
- static const size_t bogus_size = 0xdec0ded1dec0ded2LLU;
+ static const key_t bogus_key = (key_t)0xeca86420fdb97531ULL;
+ static const int bogus_id = 0xdefaced1;
+ static const int bogus_cmd = 0xdefaced2;
+ static void * const bogus_addr = (void *) -1L;
+ static const size_t bogus_size = 0xdec0ded1dec0ded2ULL;
static const int bogus_flags = 0xface1e55;
int rc;
@@ -74,6 +77,15 @@ main(void)
printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
atexit(cleanup);
+ assert(shmctl(bogus_id, bogus_cmd, NULL) == -1);
+ printf("shmctl\\(%d, (IPC_64\\|)?%#x /\\* SHM_\\?\\?\\? \\*/, "
+ "NULL\\) += %s\n",
+ bogus_id, bogus_cmd, sprintrc_grep(-1));
+
+ assert(shmctl(bogus_id, IPC_STAT, bogus_addr) == -1);
+ printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += %s\n",
+ bogus_id, bogus_addr, sprintrc_grep(-1));
+
if (shmctl(id, IPC_STAT, &ds))
perror_msg_and_skip("shmctl IPC_STAT");
printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{shm_perm=\\{uid=%u, gid=%u, "
@@ -88,6 +100,13 @@ main(void)
(unsigned) ds.shm_atime, (unsigned) ds.shm_dtime,
(unsigned) ds. shm_ctime);
+ if (shmctl(id, IPC_SET, &ds))
+ perror_msg_and_skip("shmctl IPC_SET");
+ printf("shmctl\\(%d, (IPC_64\\|)?IPC_SET, \\{shm_perm=\\{uid=%u, gid=%u, "
+ "mode=%#o\\}, ...\\}\\) += 0\n",
+ id, (unsigned) ds.shm_perm.uid, (unsigned) ds.shm_perm.gid,
+ (unsigned) ds.shm_perm.mode);
+
int max = shmctl(0, SHM_INFO, &ds);
if (max < 0)
perror_msg_and_skip("shmctl SHM_INFO");
diff --git a/tests/semop.c b/tests/semop.c
index 214ce32..01cd4ce 100644
--- a/tests/semop.c
+++ b/tests/semop.c
@@ -1,11 +1,16 @@
#include "tests.h"
+#include <assert.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include "xlat.h"
+#include "xlat/semop_flags.h"
+
union semun
{
int val;
@@ -26,6 +31,14 @@ cleanup(void)
int
main(void)
{
+ static const int bogus_semid = 0xfdb97531;
+ static void * const bogus_sops = (void *) -1L;
+ static const unsigned bogus_nsops = 0xdeadbeef;
+
+ static const struct timespec ts_data = { 1, 123456789 };
+
+ struct timespec *ts = tail_memdup(&ts_data, sizeof(*ts));
+
id = semget(IPC_PRIVATE, 1, 0600);
if (id < 0)
perror_msg_and_skip("semget");
@@ -36,10 +49,32 @@ main(void)
perror_msg_and_skip("semctl");
struct sembuf *const sem_b = tail_alloc(sizeof(*sem_b));
+ struct sembuf *const sem_b2 = tail_alloc(sizeof(*sem_b2));
+
+ assert(semop(bogus_semid, NULL, bogus_nsops) == -1);
+ printf("semop(%d, NULL, %u) = %s\n",
+ bogus_semid, bogus_nsops, sprintrc(-1));
+
+ assert(semop(bogus_semid, bogus_sops, 1) == -1);
+ printf("semop(%d, %p, %u) = %s\n",
+ bogus_semid, bogus_sops, 1, sprintrc(-1));
+
sem_b->sem_num = 0;
sem_b->sem_op = 1;
sem_b->sem_flg = SEM_UNDO;
+ sem_b2->sem_num = 0xface;
+ sem_b2->sem_op = 0xf00d;
+ sem_b2->sem_flg = 0xbeef;
+
+ assert(semop(bogus_semid, sem_b2, bogus_nsops) == -1);
+ printf("semop(%d, [{%hu, %hd, %s%s%#hx}, %p], %u) = %s\n",
+ bogus_semid, sem_b2->sem_num, sem_b2->sem_op,
+ sem_b2->sem_flg & SEM_UNDO ? "SEM_UNDO|" : "",
+ sem_b2->sem_flg & IPC_NOWAIT ? "IPC_NOWAIT|" : "",
+ sem_b2->sem_flg & ~(SEM_UNDO | IPC_NOWAIT),
+ sem_b2 + 1, bogus_nsops, sprintrc(-1));
+
if (semop(id, sem_b, 1))
perror_msg_and_skip("semop, 1");
printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", id);
@@ -49,6 +84,36 @@ main(void)
perror_msg_and_skip("semop, -1");
printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", id);
+ assert(semtimedop(bogus_semid, NULL, bogus_nsops, NULL) == -1);
+ printf("semtimedop(%d, NULL, %u, NULL) = %s\n",
+ bogus_semid, bogus_nsops, sprintrc(-1));
+
+ assert(semtimedop(id, sem_b + 1, 1, ts + 1) == -1);
+ printf("semtimedop(%d, %p, 1, %p) = %s\n",
+ id, sem_b + 1, ts + 1, sprintrc(-1));
+
+ assert(semtimedop(bogus_semid, sem_b2, bogus_nsops, ts) == -1);
+ printf("semtimedop(%d, [{%hu, %hd, %s%s%#hx}, %p], %u, {%jd, %jd}) = "
+ "%s\n",
+ bogus_semid, sem_b2->sem_num, sem_b2->sem_op,
+ sem_b2->sem_flg & SEM_UNDO ? "SEM_UNDO|" : "",
+ sem_b2->sem_flg & IPC_NOWAIT ? "IPC_NOWAIT|" : "",
+ sem_b2->sem_flg & ~(SEM_UNDO | IPC_NOWAIT),
+ sem_b2 + 1, bogus_nsops,
+ (intmax_t) ts->tv_sec, (intmax_t) ts->tv_nsec,
+ sprintrc(-1));
+
+ sem_b->sem_op = 1;
+ if (semtimedop(id, sem_b, 1, NULL))
+ perror_msg_and_skip("semtimedop, 1");
+ printf("semtimedop(%d, [{0, 1, SEM_UNDO}], 1, NULL) = 0\n", id);
+
+ sem_b->sem_op = -1;
+ if (semtimedop(id, sem_b, 1, ts))
+ perror_msg_and_skip("semtimedop, -1");
+ printf("semtimedop(%d, [{0, -1, SEM_UNDO}], 1, {%jd, %jd}) = 0\n", id,
+ (intmax_t) ts->tv_sec, (intmax_t) ts->tv_nsec);
+
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/semop.test b/tests/semop.test
index 7e8f32c..3e77d2f 100755
--- a/tests/semop.test
+++ b/tests/semop.test
@@ -3,4 +3,4 @@
# Check semop syscall decoding.
. "${srcdir=.}/init.sh"
-run_strace_match_diff -a32
+run_strace_match_diff -a32 -e trace=semop,semtimedop
diff --git a/tests/shmxt.c b/tests/shmxt.c
index 8e087f3..4f073d7 100644
--- a/tests/shmxt.c
+++ b/tests/shmxt.c
@@ -1,4 +1,5 @@
#include "tests.h"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
@@ -26,6 +27,13 @@ main(void)
perror_msg_and_skip("shmget");
atexit(cleanup);
+ assert(shmat(0xfdb97531, (void *) (unsigned long) 0xdec0ded1dec0ded2ULL,
+ (int)0xffffffff) == (void *)-1);
+ printf("%s(%d, %p, SHM_REMAP|SHM_RDONLY|SHM_RND|0xffff8fff) = %s\n",
+ SHMAT, 0xfdb97531,
+ (void *) (unsigned long) 0xdec0ded1dec0ded2ULL,
+ sprintrc(-1));
+
shmat(id, NULL, SHM_REMAP);
printf("%s(%d, NULL, SHM_REMAP) = -1 %s (%m)\n",
SHMAT, id, errno2name());
@@ -35,6 +43,9 @@ main(void)
perror_msg_and_skip("shmat SHM_RDONLY");
printf("%s(%d, NULL, SHM_RDONLY) = %p\n", SHMAT, id, shmaddr);
+ assert(shmdt(NULL) == -1);
+ printf("shmdt(NULL) = %s\n", sprintrc(-1));
+
if (shmdt(shmaddr))
perror_msg_and_skip("shmdt");
printf("shmdt(%p) = 0\n", shmaddr);
--
1.7.10.4
More information about the Strace-devel
mailing list