public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-libc Patch 0/1] Fix issue with lseek function
@ 2023-08-24 16:34 Jayaprakash, N
  2023-08-24 16:34 ` [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek() Jayaprakash, N
       [not found] ` <177E5EE7D234A063.10408@groups.io>
  0 siblings, 2 replies; 4+ messages in thread
From: Jayaprakash, N @ 2023-08-24 16:34 UTC (permalink / raw)
  To: devel; +Cc: Jayaprakash N

This patch fixes a corner case issue with the lseek function.
The issue is captured in  
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4531

Jayaprakash N (1):
  edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()

 StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108015): https://edk2.groups.io/g/devel/message/108015
Mute This Topic: https://groups.io/mt/100938748/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()
  2023-08-24 16:34 [edk2-devel] [edk2-libc Patch 0/1] Fix issue with lseek function Jayaprakash, N
@ 2023-08-24 16:34 ` Jayaprakash, N
  2023-08-24 23:39   ` Pedro Falcato
       [not found] ` <177E5EE7D234A063.10408@groups.io>
  1 sibling, 1 reply; 4+ messages in thread
From: Jayaprakash, N @ 2023-08-24 16:34 UTC (permalink / raw)
  To: devel; +Cc: Jayaprakash N, Rebecca Cran, Michael D Kinney, Kloper Dimitry

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531

Python code opens console file descriptor and uses lseek()
with position == 0 and SEEK_CUR as
'do nothing, check console is alive' operation.

Current implementation of daConsole ignores whence argument,
this is wrong in case lseek(0, SEEK_CUR) will send cursor to (0,0).
This fix is not generic, but solves the particular situation.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jayaprakash N <n.jayaprakash@intel.com>
Signed-off-by: Kloper Dimitry <dimitry.kloper@intel.com>
---
 StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
index 56571af..ba031d6 100644
--- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
+++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
@@ -141,8 +141,16 @@ da_ConSeek(
     EFIerrno = RETURN_UNSUPPORTED;
     return -1;
   }
-  // Everything is OK to do the final verification and "seek".
+
   Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+
+  if(Position == 0 && whence == SEEK_CUR) {
+    CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
+    CursorPos.XYpos.Row     = (UINT32)Proto->Mode->CursorRow;
+    return CursorPos.Offset;
+  }
+
+  // Everything is OK to do the final verification and "seek".
   CursorPos.Offset = Position;
 
   EFIerrno = Proto->SetCursorPosition(Proto,
-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108016): https://edk2.groups.io/g/devel/message/108016
Mute This Topic: https://groups.io/mt/100938751/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()
  2023-08-24 16:34 ` [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek() Jayaprakash, N
@ 2023-08-24 23:39   ` Pedro Falcato
  0 siblings, 0 replies; 4+ messages in thread
From: Pedro Falcato @ 2023-08-24 23:39 UTC (permalink / raw)
  To: devel, n.jayaprakash; +Cc: Rebecca Cran, Michael D Kinney, Kloper Dimitry

On Thu, Aug 24, 2023 at 5:34 PM Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531
>
> Python code opens console file descriptor and uses lseek()
> with position == 0 and SEEK_CUR as
> 'do nothing, check console is alive' operation.
>
> Current implementation of daConsole ignores whence argument,
> this is wrong in case lseek(0, SEEK_CUR) will send cursor to (0,0).
> This fix is not generic, but solves the particular situation.
>
> Cc: Rebecca Cran <rebecca@bsdio.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Jayaprakash N <n.jayaprakash@intel.com>
> Signed-off-by: Kloper Dimitry <dimitry.kloper@intel.com>
> ---
>  StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> index 56571af..ba031d6 100644
> --- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> +++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> @@ -141,8 +141,16 @@ da_ConSeek(
>      EFIerrno = RETURN_UNSUPPORTED;
>      return -1;
>    }
> -  // Everything is OK to do the final verification and "seek".
> +
>    Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
> +
> +  if(Position == 0 && whence == SEEK_CUR) {
> +    CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
> +    CursorPos.XYpos.Row     = (UINT32)Proto->Mode->CursorRow;
> +    return CursorPos.Offset;
> +  }
> +
> +  // Everything is OK to do the final verification and "seek".
>    CursorPos.Offset = Position;
>
>    EFIerrno = Proto->SetCursorPosition(Proto,
> --
> 2.40.0.windows.1

ttys are historically not seekable devices.

per Linux lseek(2): "On Linux, using lseek() on a terminal device
fails with the error ESPIPE"

So this function (and consequently this patch) is wrong.

-- 
Pedro


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108025): https://edk2.groups.io/g/devel/message/108025
Mute This Topic: https://groups.io/mt/100938751/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()
       [not found] ` <177E5EE7D234A063.10408@groups.io>
@ 2023-08-25 10:15   ` Jayaprakash, N
  0 siblings, 0 replies; 4+ messages in thread
From: Jayaprakash, N @ 2023-08-25 10:15 UTC (permalink / raw)
  To: devel@edk2.groups.io, Jayaprakash, N
  Cc: Rebecca Cran, Kinney, Michael D, Kloper, Dimitry

Reviewed the changes and it looks good.
Also verified that the fix solves the problem.

Reviewed-by : Jayaprakash N <n.jayaprakash@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jayaprakash, N
Sent: Thursday, August 24, 2023 10:04 PM
To: devel@edk2.groups.io
Cc: Jayaprakash, N <n.jayaprakash@intel.com>; Rebecca Cran <rebecca@bsdio.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Kloper, Dimitry <dimitry.kloper@intel.com>
Subject: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531

Python code opens console file descriptor and uses lseek() with position == 0 and SEEK_CUR as 'do nothing, check console is alive' operation.

Current implementation of daConsole ignores whence argument, this is wrong in case lseek(0, SEEK_CUR) will send cursor to (0,0).
This fix is not generic, but solves the particular situation.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jayaprakash N <n.jayaprakash@intel.com>
Signed-off-by: Kloper Dimitry <dimitry.kloper@intel.com>
---
 StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
index 56571af..ba031d6 100644
--- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
+++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
@@ -141,8 +141,16 @@ da_ConSeek(
     EFIerrno = RETURN_UNSUPPORTED;
     return -1;
   }
-  // Everything is OK to do the final verification and "seek".
+
   Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+
+  if(Position == 0 && whence == SEEK_CUR) {
+    CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
+    CursorPos.XYpos.Row     = (UINT32)Proto->Mode->CursorRow;
+    return CursorPos.Offset;
+  }
+
+  // Everything is OK to do the final verification and "seek".
   CursorPos.Offset = Position;
 
   EFIerrno = Proto->SetCursorPosition(Proto,
--
2.40.0.windows.1








-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108035): https://edk2.groups.io/g/devel/message/108035
Mute This Topic: https://groups.io/mt/100952873/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-25 10:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 16:34 [edk2-devel] [edk2-libc Patch 0/1] Fix issue with lseek function Jayaprakash, N
2023-08-24 16:34 ` [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek() Jayaprakash, N
2023-08-24 23:39   ` Pedro Falcato
     [not found] ` <177E5EE7D234A063.10408@groups.io>
2023-08-25 10:15   ` Jayaprakash, N

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox