patch for linc on i386-gnu
- From: Marcus Brinkmann <Marcus Brinkmann ruhr-uni-bochum de>
- To: orbit-list gnome org
- Subject: patch for linc on i386-gnu
- Date: Sun, 13 Oct 2002 16:55:25 +0200
Hi,
in linc 0.5.3, src/linc-protocols.c:
static char linc_tmpdir [PATH_MAX] = "";
void
linc_set_tmpdir (const char *dir)
{
strncpy (linc_tmpdir, dir, PATH_MAX);
linc_tmpdir [PATH_MAX - 1] = '\0';
make_local_tmpdir (linc_tmpdir);
}
This code is based on the assumption that PATH_MAX is always defined. But
POSIX.1 defines PATH_MAX as optional. The real limit can be determined at
run time with pathconf. However, even that can return -1 if there is no
limit. This is not hypothetical: The GNU/Hurd system does not define
PATH_MAX and pathconf returns -1.
It is very easy to fix the code by using dynamic allocation. Please
consider applying the following patch.
Thanks,
Marcus
2002-10-13 Marcus Brinkmann <marcus@gnu.org>
* src/linc-protocols.c (linc_tmpdir): Change type to char * and
remove initializer.
(linc_set_tmpdir): Dynamically allocate a large enough buffer for
linc_tmpdir.
(linc_get_tmpdir): Fall back to "" if linc_tmpdir is not set.
(linc_protocol_get_sockaddr_unix): Likewise.
--- linc-protocols.c.org 2002-10-13 18:46:47.000000000 +0200
+++ linc-protocols.c 2002-10-13 18:55:12.000000000 +0200
@@ -20,7 +20,7 @@
#undef LOCAL_DEBUG
-static char linc_tmpdir [PATH_MAX] = "";
+static char *linc_tmpdir;
/*
* make_local_tmpdir:
@@ -82,9 +82,11 @@
void
linc_set_tmpdir (const char *dir)
{
- strncpy (linc_tmpdir, dir, PATH_MAX);
+ if (linc_tmpdir)
+ g_free (linc_tmpdir);
+ linc_tmpdir = g_malloc (strlen (dir) + 1);
- linc_tmpdir [PATH_MAX - 1] = '\0';
+ strcpy (linc_tmpdir, dir);
make_local_tmpdir (linc_tmpdir);
}
@@ -101,7 +103,7 @@
char *
linc_get_tmpdir (void)
{
- return g_strdup (linc_tmpdir);
+ return g_strdup (linc_tmpdir ? linc_tmpdir : "");
}
#ifdef HAVE_SOCKADDR_SA_LEN
@@ -400,7 +402,8 @@
gettimeofday (&t, NULL);
g_snprintf (buf, sizeof (buf),
- "%s/linc-%x-%x-%x%x", linc_tmpdir,
+ "%s/linc-%x-%x-%x%x",
+ linc_tmpdir ? linc_tmpdir : "",
pid, idx++,
(guint) (rand() ^ t.tv_sec),
(guint) (idx ^ t.tv_usec));
--
`Rhubarb is no Egyptian god.' GNU http://www.gnu.org marcus@gnu.org
Marcus Brinkmann The Hurd http://www.gnu.org/software/hurd/
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]