All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	Alexander Graf <agraf@suse.de>, Cornelia Huck <cohuck@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	David Hildenbrand <david@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Bjoern Walk <bwalk@linux.vnet.ibm.com>,
	Pierre Morel <pmorel@linux.vnet.ibm.com>,
	Halil Pasic <pasic@linux.vnet.ibm.com>,
	"Jason J . Herne" <jjherne@linux.vnet.ibm.com>,
	"Collin L. Walling" <walling@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH] s390-ccw: print carriage return with new lines
Date: Fri, 20 Oct 2017 13:28:05 +0200	[thread overview]
Message-ID: <0a308495-5daa-8bce-f287-d4fd5360122d@redhat.com> (raw)
In-Reply-To: <b4a828b6-b563-55f0-2952-8a3447a8a30a@de.ibm.com>

On 20.10.2017 13:02, Christian Borntraeger wrote:
> 
> 
> On 10/20/2017 12:41 PM, Christian Borntraeger wrote:
> [...]
>>>> @@ -76,17 +76,28 @@ static int _strlen(const char *str)
>>>>  long write(int fd, const void *str, size_t len)
>>>>  {
>>>>      WriteEventData *sccb = (void *)_sccb;
>>>> +    const char *p;
>>>> +    size_t data_len = 0;
>>>>  
>>>>      if (fd != 1 && fd != 2) {
>>>>          return -EIO;
>>>>      }
>>>>  
>>>> -    sccb->h.length = sizeof(WriteEventData) + len;
>>>> +    for (p = str; *p; ++p) {
>>>> +        if (data_len > SCCB_DATA_LEN - 1) {
>>>> +            return -EFBIG;
>>>> +        }
>>>> +        if (*p == '\n') {
>>>> +            sccb->data[data_len++] = '\r';
>>>> +        }
>>>> +        sccb->data[data_len++] = *p;
>>>> +    }
>>>> +
>>>> +    sccb->h.length = sizeof(WriteEventData) + data_len;
>>>
>>> This subtly changes the semantics of the write() function from an
>>> explicitly passed in "len" argument to NULL termination determined
>>> sizing, no?
>>>
>>> In that case, wouldn't it make sense to either remove the len argument
>>> altogether or keep respecting it?
>>
>> Yes, well spotted.
>> The write function is used in other code (SLOF related network boot),
>> so we should change it to respect the length, I think.
> 
> Something like this on top?
> 
> --- a/pc-bios/s390-ccw/sclp.c
> +++ b/pc-bios/s390-ccw/sclp.c
> @@ -83,7 +83,7 @@ long write(int fd, const void *str, size_t len)
>          return -EIO;
>      }
>  
> -    for (p = str; *p; ++p) {
> +    for (p = str; len ; ++p, len--) {

I'd maybe rather use "len > 0" as end condition, but that's just
cosmetics. Anyway, patch looks fine to me with one of these changes.
And for what it's worth, SLOF is doing a similar '\n' -> '\r\n'
convertion in its write function (see e.g.
https://github.com/aik/SLOF/blob/master/llfw/clib/iolib.c), so I think
this is the right way to go here, too.

 Thomas

  parent reply	other threads:[~2017-10-20 11:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 10:25 [Qemu-devel] [PATCH] s390-ccw: print carriage return with new lines Christian Borntraeger
2017-10-20 10:30 ` Alexander Graf
2017-10-20 10:41   ` Christian Borntraeger
2017-10-20 11:02     ` Christian Borntraeger
2017-10-20 11:09       ` Alexander Graf
2017-10-20 11:18         ` Christian Borntraeger
2017-10-20 11:28       ` Thomas Huth [this message]
2017-10-20 13:48       ` Farhan Ali
2017-10-25  5:55         ` Christian Borntraeger
2017-10-20 11:31 ` Cornelia Huck
2017-10-20 12:27   ` Christian Borntraeger
2017-10-20 12:41     ` Cornelia Huck
2017-10-20 11:37 ` Halil Pasic
2017-10-25 19:49   ` Collin L. Walling
2017-10-25 22:24     ` Halil Pasic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a308495-5daa-8bce-f287-d4fd5360122d@redhat.com \
    --to=thuth@redhat.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=bwalk@linux.vnet.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=jjherne@linux.vnet.ibm.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=pmorel@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=walling@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.