Bug 1464409 - shp.fdstatus may be accessed with -1 offset, corrupting last element of shp.fdptrs
Summary: shp.fdstatus may be accessed with -1 offset, corrupting last element of shp.f...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: ksh
Version: 27
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Siteshwar Vashisht
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: 1463312
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-06-23 11:27 UTC by Siteshwar Vashisht
Modified: 2020-07-16 09:53 UTC (History)
5 users (show)

Fixed In Version: ksh-20120801-42.fc28
Clone Of: 1463312
Environment:
Last Closed: 2017-08-29 16:43:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Fix memory corruption caused by accessing array with negative index (2.21 KB, patch)
2017-08-28 13:18 UTC, Siteshwar Vashisht
kdudka: review-
Details | Diff
Fix memory corruption caused by accessing array with negative index (2.12 KB, patch)
2017-08-28 16:09 UTC, Siteshwar Vashisht
kdudka: review+
Details | Diff

Comment 1 Jan Kurik 2017-08-15 08:57:49 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 27 development cycle.
Changing version to '27'.

Comment 2 Siteshwar Vashisht 2017-08-28 13:18:34 UTC
Created attachment 1319079 [details]
Fix memory corruption caused by accessing array with negative index

Comment 3 Kamil Dudka 2017-08-28 15:48:24 UTC
Comment on attachment 1319079 [details]
Fix memory corruption caused by accessing array with negative index

> diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c
> --- a/src/cmd/ksh93/sh/io.c
> +++ b/src/cmd/ksh93/sh/io.c
> @@ -403,38 +403,50 @@ static short		filemapsize;
>  
>  /* ======== input output and file copying ======== */
>  
> -int  sh_iovalidfd(Shell_t *shp, int fd)
> +bool  sh_iovalidfd(Shell_t *shp, int fd)
>  {
>  	Sfio_t		**sftable = shp->sftable;
>  	int		max,n, **fdptrs = shp->fdptrs;
> -	unsigned char	*fdstatus = shp->fdstatus;
> +	unsigned int	*fdstatus = shp->fdstatus;

This looks incorrect to me.  shp->fdstatus is defined as (unsigned char *)
in <ksh93/include/defs.h>.  We should not cast it to an incompatible pointer
type just in this function because it would result in undefined behavior.

Comment 4 Siteshwar Vashisht 2017-08-28 16:09:04 UTC
Created attachment 1319143 [details]
Fix memory corruption caused by accessing array with negative index

Comment 5 Kamil Dudka 2017-08-28 16:17:10 UTC
Comment on attachment 1319143 [details]
Fix memory corruption caused by accessing array with negative index

Looks good.


Note You need to log in before you can comment on or make changes to this bug.