This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

BZ#15380: Fix initstate error return



From Bugzilla:
"POSIX.1-2001 says:

    RETURN VALUE
       If initstate() is called with size less than 8, it shall return
       NULL.

glibc sets errno to EINVAL for this case, but does not return NULL, thus
violating the standard."

Here's a patch to fix this, ok to commit?

Andreas

2013-04-27  Andreas Jaeger  <aj@suse.de>

	[BZ #15380]
	* stdlib/random.c (weak_alias): Return NULL if
	__initstate fails.

diff --git a/stdlib/random.c b/stdlib/random.c
index 3ed610d..1083973 100644
--- a/stdlib/random.c
+++ b/stdlib/random.c
@@ -234,16 +234,17 @@ __initstate (seed, arg_state, n)
      size_t n;
 {
   int32_t *ostate;
+  int ret;

   __libc_lock_lock (lock);

   ostate = &unsafe_state.state[-1];

-  __initstate_r (seed, arg_state, n, &unsafe_state);
+  ret = __initstate_r (seed, arg_state, n, &unsafe_state);

   __libc_lock_unlock (lock);

-  return (char *) ostate;
+  return (ret == -1) ? NULL : (char *) ostate;
 }

 weak_alias (__initstate, initstate)

--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]