mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 12:28:48 +02:00
Add tests for '=' in names and values.
2003-08-07 Matthias Clasen <maclas@gmx.de> * tests/env-test.c: Add tests for '=' in names and values. * glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a declaration for environ. (#119338)
This commit is contained in:
parent
4d2921959e
commit
96838a7a88
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
2003-08-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* tests/env-test.c: Add tests for '=' in names and values.
|
||||||
|
|
||||||
|
* glib/gutils.c (g_setenv, g_unsetenv): Check that the variable name doesn't contain '='. Add a
|
||||||
|
declaration for environ. (#119338)
|
||||||
|
|
||||||
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
* acinclude.m4: Tighten the snprintf() test to check behaviour on zero-size buffers. (#106091)
|
||||||
|
|
||||||
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
* tests/patterntest.c: Specify test strings in UTF-8, remove all charset conversion.
|
||||||
|
@ -697,7 +697,7 @@ g_getenv (const gchar *variable)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_setenv:
|
* g_setenv:
|
||||||
* @variable: the environment variable to set.
|
* @variable: the environment variable to set, must not contain '='.
|
||||||
* @value: the value for to set the variable to.
|
* @value: the value for to set the variable to.
|
||||||
* @overwrite: whether to change the variable if it already exists.
|
* @overwrite: whether to change the variable if it already exists.
|
||||||
*
|
*
|
||||||
@ -716,6 +716,7 @@ g_setenv (const gchar *variable,
|
|||||||
gboolean overwrite)
|
gboolean overwrite)
|
||||||
{
|
{
|
||||||
gint result;
|
gint result;
|
||||||
|
g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
|
||||||
#ifdef HAVE_SETENV
|
#ifdef HAVE_SETENV
|
||||||
result = setenv (variable, value, overwrite);
|
result = setenv (variable, value, overwrite);
|
||||||
#else
|
#else
|
||||||
@ -734,9 +735,16 @@ g_setenv (const gchar *variable,
|
|||||||
return result == 0;
|
return result == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_UNSETENV
|
||||||
|
/* According to the Single Unix Specification, environ is not in
|
||||||
|
* any system header, although unistd.h often declares it.
|
||||||
|
*/
|
||||||
|
extern char **environ;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_unsetenv:
|
* g_unsetenv:
|
||||||
* @variable: the environment variable to remove.
|
* @variable: the environment variable to remove, must not contain '='.
|
||||||
*
|
*
|
||||||
* Removes an environment variable from the environment.
|
* Removes an environment variable from the environment.
|
||||||
*
|
*
|
||||||
@ -750,11 +758,15 @@ void
|
|||||||
g_unsetenv (const gchar *variable)
|
g_unsetenv (const gchar *variable)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_UNSETENV
|
#ifdef HAVE_UNSETENV
|
||||||
|
g_return_if_fail (strchr (variable, '=') == NULL);
|
||||||
|
|
||||||
unsetenv (variable);
|
unsetenv (variable);
|
||||||
#else
|
#else
|
||||||
int i, len;
|
int i, len;
|
||||||
gchar **e, **f;
|
gchar **e, **f;
|
||||||
|
|
||||||
|
g_return_if_fail (strchr (variable, '=') == NULL);
|
||||||
|
|
||||||
len = strlen (variable);
|
len = strlen (variable);
|
||||||
|
|
||||||
/* Mess directly with the environ array.
|
/* Mess directly with the environ array.
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -42,6 +43,16 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
log (const gchar *log_domain,
|
||||||
|
GLogLevelFlags log_level,
|
||||||
|
const gchar *message,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
/* Silence g_assert () and friends.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -51,6 +62,8 @@ main (int argc, char *argv[])
|
|||||||
gchar *value1 = "works";
|
gchar *value1 = "works";
|
||||||
gchar *value2 = "again";
|
gchar *value2 = "again";
|
||||||
|
|
||||||
|
g_log_set_handler ("GLib", G_LOG_LEVEL_CRITICAL, log, NULL);
|
||||||
|
|
||||||
data = g_getenv (variable);
|
data = g_getenv (variable);
|
||||||
g_assert (data == NULL && "TEST_G_SETENV already set");
|
g_assert (data == NULL && "TEST_G_SETENV already set");
|
||||||
|
|
||||||
@ -81,5 +94,22 @@ main (int argc, char *argv[])
|
|||||||
data = g_getenv (variable);
|
data = g_getenv (variable);
|
||||||
g_assert (data == NULL && "g_unsetenv() doesn't work");
|
g_assert (data == NULL && "g_unsetenv() doesn't work");
|
||||||
|
|
||||||
|
result = g_setenv ("foo=bar", "baz", TRUE);
|
||||||
|
g_assert (!result && "g_setenv() accepts '=' in names");
|
||||||
|
|
||||||
|
result = g_setenv ("foo", "bar=baz", TRUE);
|
||||||
|
g_assert (result && "g_setenv() doesn't accept '=' in values");
|
||||||
|
data = g_getenv ("foo=bar");
|
||||||
|
g_assert (strcmp (data, "baz") == 0 && "g_getenv() doesn't support '=' in names");
|
||||||
|
data = g_getenv ("foo");
|
||||||
|
g_assert (strcmp (data, "bar=baz") == 0 && "g_getenv() doesn't support '=' in values");
|
||||||
|
|
||||||
|
g_unsetenv ("foo=bar");
|
||||||
|
data = g_getenv ("foo");
|
||||||
|
g_assert (data != NULL && "g_unsetenv() accepts '=' in names");
|
||||||
|
g_unsetenv ("foo");
|
||||||
|
data = g_getenv ("foo");
|
||||||
|
g_assert (data == NULL && "g_unsetenv() doesn't support '=' in values");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user