| www.delorie.com/archives/browse.cgi | search |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 delorie.com 44NGrmQu2895263 |
| Authentication-Results: | delorie.com; |
| dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Bl1gLgjQ | |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 582D7385841F |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1716483227; | |
| bh=TBWXPt826uekR9oV6ZEyD4CXDjVIWzPvEawub8fkO7k=; | |
| h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: | |
| List-Help:List-Subscribe:From:Reply-To:From; | |
| b=Bl1gLgjQ8Cf2DCR2izBWC8b4bwE3Pqoe+u2ZYtD9pIVqVG4713h1a62JJV8BBOFlz | |
| ZWE9yXfccSWNpKmcNJ5Alk4IehD/XfOf9/RYdg5utvIcFgXVeb1CvilzjhzHr17xVG | |
| K0E1qq2bf1wCzQzBe2+pF+Jxk8RCiLc0wUY92iE0= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 sourceware.org 2B97A3858D33 |
| ARC-Filter: | OpenARC Filter v1.0.0 sourceware.org 2B97A3858D33 |
| ARC-Seal: | i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716483205; cv=pass; |
| b=aur96jhaUQ+gJJWuI5adk050y1pCeszsMVLhvfCSdiKlqNH0k7r+VUX2TTqy43enBHFBg0CP320XL56Haf+blSffbhE8yH+yIEvnuK3eEd2Vq+/XpOxdDn1hLU80Fvf0SbE7RL7fVFUJaMZ++oFboKmolae2Me+J5/+RMU1fOi8= | |
| ARC-Message-Signature: | i=2; a=rsa-sha256; d=sourceware.org; s=key; |
| t=1716483205; c=relaxed/simple; | |
| bh=cfng9mz68XuUHfDot0o80c35SgzwS19hQeqlekB2atM=; | |
| h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: | |
| MIME-Version; | |
| b=uwYXTIteS+8yJ/QynMKLvUazvVGT8M+7Of9SMLhKxKvcKPWult8z1pk4dgTnJZN+sU5nbCfaul9dE6AWiwVimPF/N/SlDUcedVXfK6apQ2/6KZ2d+96+VhgNUfZ/qELELm2PipuSiAJky/9qBCWURvMb+ZwRXKW8c3H0TjxXZcU= | |
| ARC-Authentication-Results: | i=2; server2.sourceware.org |
| ARC-Seal: | i=1; a=rsa-sha256; t=1716483201; cv=none; |
| d=strato.com; s=strato-dkim-0002; | |
| b=Ag6McyVp8oyhu0VaLiRATufrZtSkXI6V20AcV57AycxBCI63azi0h38A0Tw9bjWvxM | |
| vlS0m/cx6Ygh3q82o++Xw4An/aCGcjDXqccHzrPD6Ev1xFWcw8YO5LcMhTeccjfrYHCF | |
| sPKWOKBKPlLmclBxFs3+8pup0zbtHssacXZ9IoGcXJvXtByrh/5qOsqlcWFSTo4BZJuo | |
| TsGHs2COXLxApQICqvzkyXTBRbUydT6c8FXLA+bSRApBHsuoOfquX95WXHkAROb02XiN | |
| NqJR+2dyYobvWnADejnWJ2N9U90/CKFbc1gx+PC+j1nMBp/0ZQ13LoBdMfyKrHrImq3m | |
| tSTw== | |
| ARC-Message-Signature: | i=1; a=rsa-sha256; c=relaxed/relaxed; t=1716483201; |
| s=strato-dkim-0002; d=strato.com; | |
| h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; | |
| bh=suBGf23P6FN0fjnjjAN6zTLYbf97k1mbpjK+bOAWAUg=; | |
| b=rHqAhd8itQ+F1f7bzrtNP7l3dv6ASRcraprTHjR133FN+N4apZqCv2dWrP4IVwXnGm | |
| vrj5TBqd/VJxm41kEVIYQe6M5QvOYmrbJQsMsakcQ/1jr49/Ltl7p4KfcILpLAAnu5KF | |
| q/3KpdnY6A8o24Qt8e4AD97yM2b/PaTyUEAKQCSS5i2QJKr+E5yYneAVt6g1k236XSxh | |
| gSBaOPPIWMcLHIpCMh5DwsFpsXD0ilyGIEK8DDEOcN62WS7bAAIvpSNhLdZ45yVs0fM8 | |
| 1RAz6i8E+yUkoY2oD4F1tAEi39u8zNTPdNEx8ZtzEDVBtUrXJfzeVWfLQOo79+4FXSfY | |
| qOWA== | |
| ARC-Authentication-Results: | i=1; strato.com; |
| arc=none; | |
| dkim=none | |
| X-RZG-CLASS-ID: | mo00 |
| X-RZG-AUTH: | ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPC26fyUHTfX3hM/lJqGSPH4qu4hA==" |
| To: | cygwin AT cygwin DOT com |
| Subject: | sethostname does not reject a too long hostname |
| Date: | Thu, 23 May 2024 18:53:21 +0200 |
| Message-ID: | <1851973.rkMVXJk6Ph@nimes> |
| MIME-Version: | 1.0 |
| X-Spam-Status: | No, score=-3.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, |
| DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, | |
| RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, | |
| TXREP autolearn=ham autolearn_force=no version=3.4.6 | |
| X-Spam-Checker-Version: | SpamAssassin 3.4.6 (2021-04-09) on |
| server2.sourceware.org | |
| X-BeenThere: | cygwin AT cygwin DOT com |
| X-Mailman-Version: | 2.1.30 |
| List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
| List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
| List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
| From: | Bruno Haible via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | Bruno Haible <bruno AT clisp DOT org> |
| Sender: | "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com> |
The sethostname() system call is not standardized by POSIX, only by the LSB:
https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-sethostname-2.html
In particular, it should fail with EINVAL if
"len is negative or larger than the maximum allowed size".
In Cygwin 3.5.3, a too long hostname is not rejected.
Witness: The test program below, when run on the Cygwin 3.5.3 machines
on GitHub (under a user account that is in the Administrators group),
fails with the message "setting a too long hostname succeeded."
The implementation is in winsup/cygwin/net.cc line 773.
Bruno
====================== Test program essentially =====================
#include <assert.h>
#include <unistd.h>
/* for HOST_NAME_MAX */
#include <limits.h>
/* for strlen */
#include <string.h>
#include <errno.h>
#include <stdio.h>
#define TESTHOSTNAME "gnulib-hostname"
/* mingw and MSVC 9 lack geteuid, so setup a dummy value.
On Cygwin, geteuid() may return non-zero even for user accounts with
administrator privileges, so use a dummy value as well. */
#if defined __CYGWIN__
# define geteuid() 0
#endif
int
main (int argc, char *argv[])
{
char origname[HOST_NAME_MAX];
char newname[HOST_NAME_MAX];
char longname[HOST_NAME_MAX + 2];
int rcs, i;
/* skip the tests if we don't have root privilege. this does not
consider things like CAP_SYS_ADMIN (linux) or PRIV_SYS_ADMIN
(solaris), etc. systems without a working geteuid (mingw, MSVC
9) will always skip this test. */
if (geteuid () != 0)
{
fprintf (stderr, "Skipping test: insufficient permissions.\n");
return 77;
}
/* we want to ensure we can do a get/set/get check to ensure the
change is accepted. record the current name so it can be restored
later */
assert (gethostname (origname, sizeof (origname)) == 0);
/* try setting a valid hostname. if it fails -1/ENOSYS, we will
skip the test for long names as this is an indication we're using
the stub function that doesn't do anything on this platform. */
rcs = sethostname (TESTHOSTNAME, strlen (TESTHOSTNAME));
if (rcs != 0)
{
if (rcs == -1 && errno == ENOSYS)
{
fprintf (stderr,
"Skipping test: sethostname is not really implemented.\n");
return 77;
}
else if (rcs == -1
&& (errno == EPERM
|| errno == EACCES)) /* Cygwin */
{
fprintf (stderr, "Skipping test: insufficient permissions.\n");
return 77;
}
else
{
fprintf (stderr, "error setting valid hostname.\n");
return 1;
}
}
else
{
assert (gethostname (newname, sizeof (newname)) == 0);
/* On Windows, a hostname change becomes effective only after
a reboot. */
#if !(defined _WIN32 || defined __CYGWIN__)
/* if we don't get back what we put in, there is no need to
restore the original name as we will assume it was not
properly changed. */
if (strcmp (newname, TESTHOSTNAME) != 0)
{
fprintf (stderr, "set/get comparison failed.\n");
return 1;
}
#endif
}
/* glibc does allow setting a zero length name, so the lower bound
needs no test. validate that we are constrained by
HOST_NAME_MAX */
for (i = 0; i < (HOST_NAME_MAX + 1); i++)
longname[i] = 'a';
longname[i] = '\0';
rcs = sethostname (longname, (HOST_NAME_MAX + 1));
if (rcs != -1)
{
/* attempt to restore the original name. */
assert (sethostname (origname, strlen (origname)) == 0);
fprintf (stderr, "setting a too long hostname succeeded.\n");
return 1;
}
/* restore the original name. */
assert (sethostname (origname, strlen (origname)) == 0);
return 0;
}
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |