[apparmor] [patch 06/12] parser: fix /proc version file read
Seth Arnold
seth.arnold at canonical.com
Tue Dec 10 01:59:37 UTC 2013
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 <steve at nxnw.org>
Wow that valgrind really is picky. :)
Acked-by: Seth Arnold <seth.arnold at canonical.com>
> ---
> 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;
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20131209/129f0398/attachment-0001.pgp>
More information about the AppArmor
mailing list