Hi Tamar

> -----Original Message-----
> From: Tamar Christina <tamar.christ...@arm.com>
> Sent: 30 July 2020 09:28
> To: gcc-patches@gcc.gnu.org
> Cc: nd <n...@arm.com>; Richard Earnshaw <richard.earns...@arm.com>;
> Marcus Shawcroft <marcus.shawcr...@arm.com>; Kyrylo Tkachov
> <kyrylo.tkac...@arm.com>; Richard Sandiford
> <richard.sandif...@arm.com>
> Subject: [PATCH] AArch64: Fix hwasan failure in readline.
> 
> Hi All,
> 
> My previous fix added an unchecked call to fgets in the new function readline.
> fgets can fail when there's an error reading the file in which case it returns
> NULL.  It also returns NULL when the next character is EOF.
> 
> The EOF case is already covered by the existing code but the error case isn't.
> This fixes it by returning the empty string on error.
> 
> Also I now use strnlen instead of strlen to make sure we never read outside
> the
> buffer.
> 
> This was flagged by Matthew Malcomson during his hwasan work.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master? And for backport with the other patches? (haven't done
> backport yet.)

Code looks ok, but I'm wondering what kind of input triggered this. Now that we 
can exercise this code in the testsuite (thanks!) perhaps a new test is in 
order?

Thanks,
Kyrill

> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
>       * config/aarch64/driver-aarch64.c (readline): Check return value
> fgets.
> 
> --

Reply via email to