On Tue, Dec 03, 2013 at 12:12:22PM -0800, Steve Beattie wrote:
> The parser was not checking for an error when reading from
> /proc/sys/kernel/osrelease. Additionally, valgrind was complaining
> because of the uninitialized space in the buffer in between where
> the read(2) had deposited its data and where the parser was writing
> a trailing NUL to close the string. This patch fixes the above by
> writing the NUL byte at the position at the end of the read characters
> and checks for a negative result from the read() call.
> 
> Signed-off-by: Steve Beattie <[email protected]>

Wow that valgrind really is picky. :)

Acked-by: Seth Arnold <[email protected]>

> ---
>  parser/parser_misc.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> Index: b/parser/parser_misc.c
> ===================================================================
> --- a/parser/parser_misc.c
> +++ b/parser/parser_misc.c
> @@ -311,11 +311,11 @@ static size_t kernel_af_max(void) {
>       if (!fd)
>               /* fall back to default provided during build */
>               return 0;
> -     res = read(fd, &buffer, sizeof(buffer));
> +     res = read(fd, &buffer, sizeof(buffer) - 1);
>       close(fd);
> -     if (!res)
> +     if (res <= 0)
>               return 0;
> -     buffer[sizeof(buffer)-1] = '\0';
> +     buffer[res] = '\0';
>       res = sscanf(buffer, "2.6.%d", &major);
>       if (res != 1)
>               return 0;
> 
> 

Attachment: signature.asc
Description: Digital signature

-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to