* Uninitialized structure in printing functions
@ 2017-04-21 18:07 Giacomo Tesio
2017-04-26 8:24 ` Corinna Vinschen
0 siblings, 1 reply; 5+ messages in thread
From: Giacomo Tesio @ 2017-04-21 18:07 UTC (permalink / raw)
To: newlib
[-- Attachment #1: Type: text/plain, Size: 155 bytes --]
Hi, during the port to Jehanne, I had issues with the uninitialized
uio structure in several printing functions.
The attached patch fixes them.
Giacomo
[-- Attachment #2: newlib.uio.diff --]
[-- Type: text/plain, Size: 3361 bytes --]
diff --git a/newlib/libc/machine/powerpc/vfprintf.c b/newlib/libc/machine/powerpc/vfprintf.c
index d264e26..e68b5ed 100644
--- a/newlib/libc/machine/powerpc/vfprintf.c
+++ b/newlib/libc/machine/powerpc/vfprintf.c
@@ -380,7 +380,7 @@ _DEFUN (_VFPRINTF_R, (data, fp, fmt0, ap),
int size; /* size of converted field or string */
char *xdigs = NULL; /* digits for [xX] conversion */
#define NIOV 8
- struct __suio uio; /* output information: summary */
+ struct __suio uio = {0, 0, 0}; /* output information: summary */
struct __siov iov[NIOV];/* ... and individual io vectors */
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
char ox[2]; /* space for 0x hex-prefix */
diff --git a/newlib/libc/stdio/fputs.c b/newlib/libc/stdio/fputs.c
index 75f65d9..0fda237 100644
--- a/newlib/libc/stdio/fputs.c
+++ b/newlib/libc/stdio/fputs.c
@@ -117,7 +117,7 @@ _DEFUN(_fputs_r, (ptr, s, fp),
{
#ifdef _FVWRITE_IN_STREAMIO
int result;
- struct __suio uio;
+ struct __suio uio = {0, 0, 0};
struct __siov iov;
iov.iov_base = s;
diff --git a/newlib/libc/stdio/fputws.c b/newlib/libc/stdio/fputws.c
index bb2fa6d..e5a333c 100644
--- a/newlib/libc/stdio/fputws.c
+++ b/newlib/libc/stdio/fputws.c
@@ -126,7 +126,7 @@ _DEFUN(_fputws_r, (ptr, ws, fp),
size_t nbytes;
char buf[BUFSIZ];
#ifdef _FVWRITE_IN_STREAMIO
- struct __suio uio;
+ struct __suio uio = {0, 0, 0};
struct __siov iov;
_newlib_flockfile_start (fp);
diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c
index 6b3ff90..2e39cb0 100644
--- a/newlib/libc/stdio/fwrite.c
+++ b/newlib/libc/stdio/fwrite.c
@@ -149,7 +149,7 @@ _DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
{
size_t n;
#ifdef _FVWRITE_IN_STREAMIO
- struct __suio uio;
+ struct __suio uio = {0, 0, 0};
struct __siov iov;
iov.iov_base = buf;
diff --git a/newlib/libc/stdio/puts.c b/newlib/libc/stdio/puts.c
index 7467371..d154406 100644
--- a/newlib/libc/stdio/puts.c
+++ b/newlib/libc/stdio/puts.c
@@ -81,7 +81,7 @@ _DEFUN(_puts_r, (ptr, s),
#ifdef _FVWRITE_IN_STREAMIO
int result;
size_t c = strlen (s);
- struct __suio uio;
+ struct __suio uio = {0, 0, 0};
struct __siov iov[2];
FILE *fp;
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index ed92bb2..d4bd1c8 100644
--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -718,7 +718,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
char *xdigs = NULL; /* digits for [xX] conversion */
#ifdef _FVWRITE_IN_STREAMIO
#define NIOV 8
- struct __suio uio; /* output information: summary */
+ struct __suio uio = {0, 0, 0}; /* output information: summary */
struct __siov iov[NIOV];/* ... and individual io vectors */
register struct __siov *iovp;/* for PRINT macro */
#endif
diff --git a/newlib/libc/stdio/vfwprintf.c b/newlib/libc/stdio/vfwprintf.c
index f0179a0..15504b5 100644
--- a/newlib/libc/stdio/vfwprintf.c
+++ b/newlib/libc/stdio/vfwprintf.c
@@ -438,7 +438,7 @@ _DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap),
wchar_t *xdigs = NULL; /* digits for [xX] conversion */
#ifdef _FVWRITE_IN_STREAMIO
#define NIOV 8
- struct __suio uio; /* output information: summary */
+ struct __suio uio = {0, 0, 0}; /* output information: summary */
struct __siov iov[NIOV];/* ... and individual io vectors */
register struct __siov *iovp;/* for PRINT macro */
#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Uninitialized structure in printing functions
2017-04-21 18:07 Uninitialized structure in printing functions Giacomo Tesio
@ 2017-04-26 8:24 ` Corinna Vinschen
2017-04-26 9:35 ` Giacomo Tesio
0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2017-04-26 8:24 UTC (permalink / raw)
To: Giacomo Tesio; +Cc: newlib
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
On Apr 21 19:03, Giacomo Tesio wrote:
> Hi, during the port to Jehanne, I had issues with the uninitialized
> uio structure in several printing functions.
>
> The attached patch fixes them.
I'm puzzled what problem you're solving.
I inspected the code in question and the uio structure is always filled
with values for all three members before using it. Setting uio to 0
in all these places looks gratuitous.
Can you please explain what exactly you're observing and how setting
uio to all 0 solved this problem?
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Uninitialized structure in printing functions
2017-04-26 8:24 ` Corinna Vinschen
@ 2017-04-26 9:35 ` Giacomo Tesio
2017-04-27 14:10 ` Giacomo Tesio
0 siblings, 1 reply; 5+ messages in thread
From: Giacomo Tesio @ 2017-04-26 9:35 UTC (permalink / raw)
To: newlib
Hi Corinna,
I was trying to fix a simple "hello, world" test:
https://github.com/JehanneOS/jehanne/blob/c2982db8a2c57a3250c129c28bb395715521ec4e/qa/lib/newlib/hello.c.
During debug one of the issue I've noticed was a fault related to uio
in vfprintf.c:348: apparently uio->uio_resid was uninitialized and
actually the patch I provided fixed the test.
However with a different test I'm working on now, I've found that
zeroing the structures is not enough.
Somehow uio->uio_resid overflows there, but I wasn't able yet to
identify why or where.
Any suggestion is welcome. I supposed I've just hit an untested
combination of configure options, but actually --enable-newlib-mb is
the only configure option I'm using (except for prefix and target,
obviously).
Giacomo
2017-04-26 10:24 GMT+02:00 Corinna Vinschen <vinschen@redhat.com>:
> On Apr 21 19:03, Giacomo Tesio wrote:
>> Hi, during the port to Jehanne, I had issues with the uninitialized
>> uio structure in several printing functions.
>>
>> The attached patch fixes them.
>
> I'm puzzled what problem you're solving.
>
> I inspected the code in question and the uio structure is always filled
> with values for all three members before using it. Setting uio to 0
> in all these places looks gratuitous.
>
> Can you please explain what exactly you're observing and how setting
> uio to all 0 solved this problem?
>
>
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Uninitialized structure in printing functions
2017-04-26 9:35 ` Giacomo Tesio
@ 2017-04-27 14:10 ` Giacomo Tesio
2017-04-27 14:56 ` Giacomo Tesio
0 siblings, 1 reply; 5+ messages in thread
From: Giacomo Tesio @ 2017-04-27 14:10 UTC (permalink / raw)
To: newlib
Hi, I've just found that with -O0 both my tests and the newlib's
testsuite work as expected, even removing the uio initialization
provided in the patch.
This is a bit weird. My cross compiler is GCC 4.9.4: is it possible
that newlib is not actually tested with this version?
Giacomo
2017-04-26 11:35 GMT+02:00 Giacomo Tesio <giacomo@tesio.it>:
> Hi Corinna,
>
> I was trying to fix a simple "hello, world" test:
> https://github.com/JehanneOS/jehanne/blob/c2982db8a2c57a3250c129c28bb395715521ec4e/qa/lib/newlib/hello.c.
>
> During debug one of the issue I've noticed was a fault related to uio
> in vfprintf.c:348: apparently uio->uio_resid was uninitialized and
> actually the patch I provided fixed the test.
> However with a different test I'm working on now, I've found that
> zeroing the structures is not enough.
> Somehow uio->uio_resid overflows there, but I wasn't able yet to
> identify why or where.
>
> Any suggestion is welcome. I supposed I've just hit an untested
> combination of configure options, but actually --enable-newlib-mb is
> the only configure option I'm using (except for prefix and target,
> obviously).
>
>
>
> Giacomo
>
>
> 2017-04-26 10:24 GMT+02:00 Corinna Vinschen <vinschen@redhat.com>:
>> On Apr 21 19:03, Giacomo Tesio wrote:
>>> Hi, during the port to Jehanne, I had issues with the uninitialized
>>> uio structure in several printing functions.
>>>
>>> The attached patch fixes them.
>>
>> I'm puzzled what problem you're solving.
>>
>> I inspected the code in question and the uio structure is always filled
>> with values for all three members before using it. Setting uio to 0
>> in all these places looks gratuitous.
>>
>> Can you please explain what exactly you're observing and how setting
>> uio to all 0 solved this problem?
>>
>>
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Uninitialized structure in printing functions
2017-04-27 14:10 ` Giacomo Tesio
@ 2017-04-27 14:56 ` Giacomo Tesio
0 siblings, 0 replies; 5+ messages in thread
From: Giacomo Tesio @ 2017-04-27 14:56 UTC (permalink / raw)
To: newlib
Sorry, I've just noticed that -O0 was not enough: I also configured
newlib with --disable-newlib-fwrite-in-streamio actually removing the
uio structures altogether.
Neither -O0 nor --disable-newlib-fwrite-in-streamio were enough alone.
They are needed together to make the hello world test pass.
Giacomo
2017-04-27 16:10 GMT+02:00 Giacomo Tesio <giacomo@tesio.it>:
> Hi, I've just found that with -O0 both my tests and the newlib's
> testsuite work as expected, even removing the uio initialization
> provided in the patch.
>
> This is a bit weird. My cross compiler is GCC 4.9.4: is it possible
> that newlib is not actually tested with this version?
>
>
> Giacomo
>
> 2017-04-26 11:35 GMT+02:00 Giacomo Tesio <giacomo@tesio.it>:
>> Hi Corinna,
>>
>> I was trying to fix a simple "hello, world" test:
>> https://github.com/JehanneOS/jehanne/blob/c2982db8a2c57a3250c129c28bb395715521ec4e/qa/lib/newlib/hello.c.
>>
>> During debug one of the issue I've noticed was a fault related to uio
>> in vfprintf.c:348: apparently uio->uio_resid was uninitialized and
>> actually the patch I provided fixed the test.
>> However with a different test I'm working on now, I've found that
>> zeroing the structures is not enough.
>> Somehow uio->uio_resid overflows there, but I wasn't able yet to
>> identify why or where.
>>
>> Any suggestion is welcome. I supposed I've just hit an untested
>> combination of configure options, but actually --enable-newlib-mb is
>> the only configure option I'm using (except for prefix and target,
>> obviously).
>>
>>
>>
>> Giacomo
>>
>>
>> 2017-04-26 10:24 GMT+02:00 Corinna Vinschen <vinschen@redhat.com>:
>>> On Apr 21 19:03, Giacomo Tesio wrote:
>>>> Hi, during the port to Jehanne, I had issues with the uninitialized
>>>> uio structure in several printing functions.
>>>>
>>>> The attached patch fixes them.
>>>
>>> I'm puzzled what problem you're solving.
>>>
>>> I inspected the code in question and the uio structure is always filled
>>> with values for all three members before using it. Setting uio to 0
>>> in all these places looks gratuitous.
>>>
>>> Can you please explain what exactly you're observing and how setting
>>> uio to all 0 solved this problem?
>>>
>>>
>>> Corinna
>>>
>>> --
>>> Corinna Vinschen
>>> Cygwin Maintainer
>>> Red Hat
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-04-27 14:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-21 18:07 Uninitialized structure in printing functions Giacomo Tesio
2017-04-26 8:24 ` Corinna Vinschen
2017-04-26 9:35 ` Giacomo Tesio
2017-04-27 14:10 ` Giacomo Tesio
2017-04-27 14:56 ` Giacomo Tesio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).