From patchwork Mon Oct 5 17:11:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 40662 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAB6F393C87E; Mon, 5 Oct 2020 17:12:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAB6F393C87E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601917921; bh=PXeZvZlrWk1Qz57Bt3DnDG5zmNWsQkPAPhxDl/3bbTk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oD/fzp85HXANrUvcnSDhO8VJWrCvInW6/QwQfPDE1vmASka0y5f74HO7vb+so2GNL s6ot/iSdnYL7FywfibTgSigs66GWciFy1NM4CNts7Y5cVxUwD+8+NSOvTb/s0m16ko 2RBYs2H0oiyDsKB5L5Vw/Pod8m0HGMJmu0T22nCc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id DFB163857C7E for ; Mon, 5 Oct 2020 17:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DFB163857C7E Received: by mail-qt1-x843.google.com with SMTP id n10so10266856qtv.3 for ; Mon, 05 Oct 2020 10:11:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=PXeZvZlrWk1Qz57Bt3DnDG5zmNWsQkPAPhxDl/3bbTk=; b=BqZsDK+zr3BasIntQy9A7H0EbGznWuVZ3DezjNkM8l+HLoOO0FB/6n4906mQQ1OdGQ pIrvuUkDve8hOlH3eC5HwkBJnMV38T2Jv5M8vvd7m47yyZbxUo67EP5OgcII2SFjBDIj NhByfuwhQgL3JjCCnnXTs2ZgIgK/8ZBe1gQbq9bgO1w7Vhj/tcF9MEsh1MhMMilF6oCL NtrLT32f5H4Jq3NDatCuONk+w+yKB6J7FnX7lO8hp9uyW30pPnSnrv6COhoxbgJMa51Q FhOnwA6ZIV9quFYwSepGuzPyFIqhfUKXMaNPa6yT92pGSYXg7VOkRIDpdhd8Xw+j2dYP ilaw== X-Gm-Message-State: AOAM530FYFXFSn3/OLTSdKlq5vfgsHP5apk092KqHp+cFLak7LbKq4pp +Y7M6erTcSEJem1SyUQZp9Gs5KUWR/8yMw== X-Google-Smtp-Source: ABdhPJzugnBnh2aT/WF48or8WJkblKIPztw/q1r8zt/gW55KybF7a6xNJ4YPMQ9Qy+jhjmMzhieTBQ== X-Received: by 2002:ac8:6a01:: with SMTP id t1mr910021qtr.26.1601917917958; Mon, 05 Oct 2020 10:11:57 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id h40sm249987qte.59.2020.10.05.10.11.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 10:11:57 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/2] sysvipc: Fix IPC_INFO and SHM_INFO handling [BZ #26636] Date: Mon, 5 Oct 2020 14:11:51 -0300 Message-Id: <20201005171152.676380-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Read the shm /proc tunables as 64-bit values to handle 32-bit binaries running on 64-bit kernels. - Handle shmmax value larger than INT_MAX. - Move SHM_STAT_ANY prior SHM_STAT to avoid the test finish early. --- Both commands are Linux extensions where the third argument is either a 'struct shminfo' (IPC_INFO) or a 'struct shm_info' (SHM_INFO) instead of 'struct shmid_ds'. And their information does not contain any time related fields, so there is no need to extra conversion for __IPC_TIME64. The regression testcase checks for Linux specifix SysV ipc message control extension. For SHM_INFO it tries to match the values against the tunable /proc values and for MSG_STAT/MSG_STAT_ANY it check if the create\ shared memory is within the global list returned by the kernel. Checked on x86_64-linux-gnu and on i686-linux-gnu (Linux v5.4 and on Linux v4.15). --- sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/shmctl.c | 24 ++- sysdeps/unix/sysv/linux/tst-sysvshm-linux.c | 184 ++++++++++++++++++++ 3 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/tst-sysvshm-linux.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index a54eb75d74..5a78614457 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -101,7 +101,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \ test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \ - tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux + tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c index 76d88441f1..1d19a798b1 100644 --- a/sysdeps/unix/sysv/linux/shmctl.c +++ b/sysdeps/unix/sysv/linux/shmctl.c @@ -90,8 +90,15 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) struct kernel_shmid64_ds kshmid, *arg = NULL; if (buf != NULL) { - shmid64_to_kshmid64 (buf, &kshmid); - arg = &kshmid; + /* This is a Linux extension where kernel expects either a + 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */ + if (cmd == IPC_INFO || cmd == SHM_INFO) + arg = (struct kernel_shmid64_ds *) buf; + else + { + shmid64_to_kshmid64 (buf, &kshmid); + arg = &kshmid; + } } # ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T if (cmd == IPC_SET) @@ -107,7 +114,6 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) switch (cmd) { - case IPC_INFO: case IPC_STAT: case SHM_STAT: case SHM_STAT_ANY: @@ -168,8 +174,15 @@ __shmctl (int shmid, int cmd, struct shmid_ds *buf) struct __shmid64_ds shmid64, *buf64 = NULL; if (buf != NULL) { - shmid_to_shmid64 (&shmid64, buf); - buf64 = &shmid64; + /* This is a Linux extension where kernel expects either a + 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */ + if (cmd == IPC_INFO || cmd == SHM_INFO) + buf64 = (struct __shmid64_ds *) buf; + else + { + shmid_to_shmid64 (&shmid64, buf); + buf64 = &shmid64; + } } int ret = __shmctl64 (shmid, cmd, buf64); @@ -178,7 +191,6 @@ __shmctl (int shmid, int cmd, struct shmid_ds *buf) switch (cmd) { - case IPC_INFO: case IPC_STAT: case SHM_STAT: case SHM_STAT_ANY: diff --git a/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c b/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c new file mode 100644 index 0000000000..1a6f389d64 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c @@ -0,0 +1,184 @@ +/* Basic tests for Linux SYSV shared memory extensions. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define SHM_MODE 0644 + +/* These are for the temporary file we generate. */ +static char *name; +static int shmid; +static long int pgsz; + +static void +remove_shm (void) +{ + /* Enforce message queue removal in case of early test failure. + Ignore error since the shm may already have being removed. */ + shmctl (shmid, IPC_RMID, NULL); +} + +static void +do_prepare (int argc, char *argv[]) +{ + TEST_VERIFY_EXIT (create_temp_file ("tst-sysvshm.", &name) != -1); +} + +#define PREPARE do_prepare + +struct test_shminfo +{ + unsigned long int shmall; + unsigned long int shmmax; + unsigned long int shmmni; +}; + +/* It tries to obtain some system-wide SysV shared memory information from + /proc to check against IPC_INFO/SHM_INFO. The /proc only returns the + tunables value of SHMALL, SHMMAX, and SHMMNI. */ + +static uint64_t +read_proc_file (const char *file) +{ + FILE *f = fopen (file, "r"); + if (f == NULL) + FAIL_UNSUPPORTED ("/proc is not mounted or %s is not available", file); + + /* Handle 32-bit binaries running on 64-bit kernels. */ + uint64_t v; + int r = fscanf (f, "%" SCNu64, &v); + TEST_VERIFY_EXIT (r == 1); + + fclose (f); + return v; +} + + +/* Check if the message queue with IDX (index into the kernel's internal + array) matches the one with KEY. The CMD is either SHM_STAT or + SHM_STAT_ANY. */ + +static bool +check_shminfo (int idx, key_t key, int cmd) +{ + struct shmid_ds shminfo; + int sid = shmctl (idx, cmd, &shminfo); + /* Ignore unused array slot returned by the kernel or information from + unknown message queue. */ + if ((sid == -1 && errno == EINVAL) || sid != shmid) + return false; + + if (sid == -1) + FAIL_EXIT1 ("shmctl with %s failed: %m", + cmd == SHM_STAT ? "SHM_STAT" : "SHM_STAT_ANY"); + + TEST_COMPARE (shminfo.shm_perm.__key, key); + TEST_COMPARE (shminfo.shm_perm.mode, SHM_MODE); + TEST_COMPARE (shminfo.shm_segsz, pgsz); + + return true; +} + +static int +do_test (void) +{ + atexit (remove_shm); + + pgsz = sysconf (_SC_PAGESIZE); + if (pgsz == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE) failed: %m"); + + key_t key = ftok (name, 'G'); + if (key == -1) + FAIL_EXIT1 ("ftok failed: %m"); + + shmid = shmget (key, pgsz, IPC_CREAT | IPC_EXCL | SHM_MODE); + if (shmid == -1) + FAIL_EXIT1 ("shmget failed: %m"); + + struct test_shminfo tipcinfo; + { + uint64_t v = read_proc_file ("/proc/sys/kernel/shmmax"); +#if LONG_MAX == INT_MAX + /* Kernel explicit clamp the value for shmmax on compat symbol (32-bit + binaries running on 64-bit kernels). */ + if (v > INT_MAX) + v = INT_MAX; +#endif + tipcinfo.shmmax = v; + } + tipcinfo.shmall = read_proc_file ("/proc/sys/kernel/shmall"); + tipcinfo.shmmni = read_proc_file ("/proc/sys/kernel/shmmni"); + + int shmidx; + + /* Note: SHM_INFO does not return a shminfo, but rather a 'struct shm_info' + and it is tricky to verify it since it returns system resources consumed + by shared memory. The shmctl implementation handles SHM_INFO as + IPC_INFO, so the IPC_INFO test should validate SHM_INFO as well. */ + + { + struct shminfo ipcinfo; + shmidx = shmctl (shmid, IPC_INFO, (struct shmid_ds *) &ipcinfo); + if (shmidx == -1) + FAIL_EXIT1 ("shmctl with IPC_INFO failed: %m"); + + TEST_COMPARE (ipcinfo.shmall, tipcinfo.shmall); + TEST_COMPARE (ipcinfo.shmmax, tipcinfo.shmmax); + TEST_COMPARE (ipcinfo.shmmni, tipcinfo.shmmni); + } + + /* We check if the created shared memory shows in the global list. */ + bool found = false; + for (int i = 0; i <= shmidx; i++) + { + /* We can't tell apart if SHM_STAT_ANY is not supported (kernel older + than 4.17) or if the index used is invalid. So it just check if + value returned from a valid call matches the created message + queue. */ + check_shminfo (i, key, SHM_STAT_ANY); + + if (check_shminfo (i, key, SHM_STAT)) + { + found = true; + break; + } + } + + if (!found) + FAIL_EXIT1 ("shmctl with SHM_STAT/SHM_STAT_ANY could not find the " + "created shared memory"); + + if (shmctl (shmid, IPC_RMID, NULL) == -1) + FAIL_EXIT1 ("shmctl failed"); + + return 0; +} + +#include From patchwork Mon Oct 5 17:11:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 40663 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D90053950C08; Mon, 5 Oct 2020 17:12:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D90053950C08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601917922; bh=VRwQLdSStv7YM8ZGhL/+IhpFvdud2hubUuCf15ctqjA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Vh9jzPRxGlQwFNNy3a+bgN44w6Ah9uiHKGK7dcB18hrs5ReRW/ACdLO1thVU9O1I8 gu+Vfdi28mzndTIbJCQCQ2IwASQRYPeq/5Rn76yY/2wX5mD4E1sKv9OCPOUpvpv5mB usueYXJu6B1a21lSTHOk6hQIjY1nSslxNRTMhc/E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by sourceware.org (Postfix) with ESMTPS id 8F5D9388C025 for ; Mon, 5 Oct 2020 17:12:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F5D9388C025 Received: by mail-qt1-x842.google.com with SMTP id n10so10266936qtv.3 for ; Mon, 05 Oct 2020 10:12:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VRwQLdSStv7YM8ZGhL/+IhpFvdud2hubUuCf15ctqjA=; b=OOrbXBWpp8dWYb/ddFL/G0PEWKFZ2AN3rnUz/eE41gIhIl0+X4+/ASlwEUtyC+IAap SWWcUxTGU+JbfonBFfoh8a4FC76JVxXzG1es3RReQn3JcHOpczE6Vn6BQrYmSpHrje8f ukz//ztEPW5LaIMxhh2MlL5GX6jIYijk1WfTuKcDXkJzaAqJVWr2NfaDyMn4vykJhgWH bJMJkrfm1NxIZJhzFkvQ56qTmPPxs76wVVM8riMBTlLBybx4zkmsAS5LdVhdZLyMIivH WNOrSn387zoH9H3ixKvD4l8VJbTV4FwdV7cHXafruE1VEKFScXCcemJwCW3eOVgt5gpn b67A== X-Gm-Message-State: AOAM5302mSC6cfH6HqTDBB1xP9GEF04ictnQslPGLCcrhUyKN82aHS/M ThQ233MgsEKMxmsCNsJtdBALwoYpOKXb8g== X-Google-Smtp-Source: ABdhPJx++Skzwtnc2SIhPV7sbdjtJCRaK1EVO5hFFEXudXzqOnY8qOs9j/tmHEAiTT8Qwzbgc3aOdw== X-Received: by 2002:ac8:27d4:: with SMTP id x20mr883097qtx.43.1601917919641; Mon, 05 Oct 2020 10:11:59 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id h40sm249987qte.59.2020.10.05.10.11.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 10:11:59 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/2] sysvipc: Return EINVAL for invalid shmctl commands Date: Mon, 5 Oct 2020 14:11:52 -0300 Message-Id: <20201005171152.676380-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201005171152.676380-1-adhemerval.zanella@linaro.org> References: <20201005171152.676380-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Handle missing SHM_STAT_ANY on __shmctl64. --- It avoids regressions on possible future commands that might require additional libc support. The downside is new commands added by newer kernels will need further glibc support. Checked on x86_64-linux-gnu and i686-linux-gnu (Linux v4.15 and v5.4). --- sysdeps/unix/sysv/linux/shmctl.c | 42 ++++++++++++++++++++++++-------- sysvipc/test-sysvipc.h | 25 +++++++++++++++++++ sysvipc/test-sysvshm.c | 5 ++++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c index 1d19a798b1..73f0b7326f 100644 --- a/sysdeps/unix/sysv/linux/shmctl.c +++ b/sysdeps/unix/sysv/linux/shmctl.c @@ -88,25 +88,47 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) { #if __IPC_TIME64 struct kernel_shmid64_ds kshmid, *arg = NULL; - if (buf != NULL) +#else + shmctl_arg_t *arg; +#endif + + switch (cmd) { - /* This is a Linux extension where kernel expects either a - 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */ - if (cmd == IPC_INFO || cmd == SHM_INFO) - arg = (struct kernel_shmid64_ds *) buf; - else + case IPC_RMID: + arg = NULL; + break; + + case IPC_SET: + case IPC_STAT: + case SHM_STAT: + case SHM_STAT_ANY: +#if __IPC_TIME64 + if (buf != NULL) { shmid64_to_kshmid64 (buf, &kshmid); arg = &kshmid; } - } # ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T - if (cmd == IPC_SET) - arg->shm_perm.mode *= 0x10000U; + if (cmd == IPC_SET) + arg->shm_perm.mode *= 0x10000U; # endif #else - shmctl_arg_t *arg = buf; + arg = buf; #endif + break; + + case IPC_INFO: + case SHM_INFO: + /* This is a Linux extension where kernel expects either a + 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */ + arg = (__typeof__ (arg)) buf; + break; + + default: + __set_errno (EINVAL); + return -1; + } + int ret = shmctl_syscall (shmid, cmd, arg); if (ret < 0) diff --git a/sysvipc/test-sysvipc.h b/sysvipc/test-sysvipc.h index 21ef6c6565..179f5e8cc9 100644 --- a/sysvipc/test-sysvipc.h +++ b/sysvipc/test-sysvipc.h @@ -107,4 +107,29 @@ first_msg_invalid_cmd (void) return invalid; } +/* Return the first invalid command SysV IPC command for shared memory. */ +static inline int +first_shm_invalid_cmd (void) +{ + const int shm_cmds[] = { + SHM_STAT, + SHM_INFO, +#ifdef SHM_STAT_ANY + SHM_STAT_ANY, +#endif + }; + + int invalid = first_common_invalid_cmd (); + for (int i = 0; i < array_length (shm_cmds); i++) + { + if (invalid == shm_cmds[i]) + { + invalid++; + i = 0; + } + } + + return invalid; +} + #endif /* _TEST_SYSV_H */ diff --git a/sysvipc/test-sysvshm.c b/sysvipc/test-sysvshm.c index f083fd280b..a1b8b4823e 100644 --- a/sysvipc/test-sysvshm.c +++ b/sysvipc/test-sysvshm.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -81,6 +83,9 @@ do_test (void) FAIL_EXIT1 ("shmget failed (errno=%d)", errno); } + TEST_COMPARE (shmctl (shmid, first_shm_invalid_cmd (), NULL), -1); + TEST_COMPARE (errno, EINVAL); + /* Get shared memory kernel information and do some sanity checks. */ struct shmid_ds shminfo; if (shmctl (shmid, IPC_STAT, &shminfo) == -1)