2015-08-08 22:53:03 +00:00
|
|
|
#include <assert.h>
|
2000-09-07 03:49:56 +00:00
|
|
|
#include <mcheck.h>
|
|
|
|
#include <nl_types.h>
|
|
|
|
#include <stdio.h>
|
2015-08-08 22:53:03 +00:00
|
|
|
#include <stdlib.h>
|
2000-09-07 03:49:56 +00:00
|
|
|
#include <string.h>
|
2015-08-08 22:53:03 +00:00
|
|
|
#include <sys/resource.h>
|
2000-09-07 03:49:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const char *msgs[] =
|
|
|
|
{
|
|
|
|
#define INPUT(str)
|
|
|
|
#define OUTPUT(str) str,
|
|
|
|
#include <intl/msgs.h>
|
|
|
|
};
|
|
|
|
#define nmsgs (sizeof (msgs) / sizeof (msgs[0]))
|
|
|
|
|
2015-08-08 22:53:03 +00:00
|
|
|
|
|
|
|
/* Test for unbounded alloca. */
|
|
|
|
static int
|
|
|
|
do_bz17905 (void)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
struct rlimit rl;
|
2016-03-16 03:16:47 +00:00
|
|
|
nl_catd result __attribute__ ((unused));
|
2015-08-08 22:53:03 +00:00
|
|
|
|
|
|
|
const int sz = 1024 * 1024;
|
|
|
|
|
|
|
|
getrlimit (RLIMIT_STACK, &rl);
|
|
|
|
rl.rlim_cur = sz;
|
|
|
|
setrlimit (RLIMIT_STACK, &rl);
|
|
|
|
|
2015-08-08 22:54:40 +00:00
|
|
|
buf = malloc (sz + 1);
|
2015-08-08 22:53:03 +00:00
|
|
|
memset (buf, 'A', sz);
|
|
|
|
buf[sz] = '\0';
|
|
|
|
setenv ("NLSPATH", buf, 1);
|
|
|
|
|
|
|
|
result = catopen (buf, NL_CAT_LOCALE);
|
|
|
|
assert (result == (nl_catd) -1);
|
|
|
|
|
|
|
|
free (buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-07 03:49:56 +00:00
|
|
|
#define ROUNDS 5
|
|
|
|
|
2014-11-05 09:54:08 +00:00
|
|
|
static int
|
|
|
|
do_test (void)
|
2000-09-07 03:49:56 +00:00
|
|
|
{
|
|
|
|
int rnd;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
mtrace ();
|
|
|
|
|
|
|
|
/* We do this a few times to stress the memory handling. */
|
|
|
|
for (rnd = 0; rnd < ROUNDS; ++rnd)
|
|
|
|
{
|
|
|
|
nl_catd cd = catopen ("libc", 0);
|
2002-09-24 04:24:25 +00:00
|
|
|
size_t cnt;
|
2000-09-07 03:49:56 +00:00
|
|
|
|
|
|
|
if (cd == (nl_catd) -1)
|
|
|
|
{
|
|
|
|
printf ("cannot load catalog: %m\n");
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go through all the messages and compare the result. */
|
|
|
|
for (cnt = 0; cnt < nmsgs; ++cnt)
|
|
|
|
{
|
|
|
|
char *trans;
|
|
|
|
|
|
|
|
trans = catgets (cd, 1, 1 + cnt,
|
2002-07-17 00:03:55 +00:00
|
|
|
"+#+# if this comes backs it's an error");
|
2000-09-07 03:49:56 +00:00
|
|
|
|
|
|
|
if (trans == NULL)
|
|
|
|
{
|
2002-09-30 07:47:16 +00:00
|
|
|
printf ("catgets return NULL for %zd\n", cnt);
|
2000-09-07 03:49:56 +00:00
|
|
|
result = 1;
|
|
|
|
}
|
2002-07-17 00:03:55 +00:00
|
|
|
else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0')
|
2000-09-07 03:49:56 +00:00
|
|
|
{
|
|
|
|
printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans);
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (catclose (cd) != 0)
|
|
|
|
{
|
|
|
|
printf ("catclose failed: %m\n");
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-08 22:53:03 +00:00
|
|
|
result += do_bz17905 ();
|
2000-09-07 03:49:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
2014-11-05 09:54:08 +00:00
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|