From 6bb28aae18f4ac530d3c9777549e0c98fc73dcd4 Mon Sep 17 00:00:00 2001 From: imp Date: Fri, 5 Jan 2018 07:09:24 +0000 Subject: [PATCH] Set dp to NULL when we free it, and tree a NULL dp as an error condition. This should prevent a double free. In addition, prevent a leak by freeing dp each loop and when we're done. CID: 1383577 Sponsored by: Netflix --- lib/libefivar/efivar-dp-xlate.c | 1 + usr.sbin/efidp/efidp.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libefivar/efivar-dp-xlate.c b/lib/libefivar/efivar-dp-xlate.c index 58c89068645a..5c9398d9f43f 100644 --- a/lib/libefivar/efivar-dp-xlate.c +++ b/lib/libefivar/efivar-dp-xlate.c @@ -663,6 +663,7 @@ path_to_dp(struct gmesh *mesh, char *path, efidp *dp) free(rp); if (rv != 0) { free(*dp); + *dp = NULL; } return (rv); } diff --git a/usr.sbin/efidp/efidp.c b/usr.sbin/efidp/efidp.c index a4db95abeeac..e12491ecabf5 100644 --- a/usr.sbin/efidp/efidp.c +++ b/usr.sbin/efidp/efidp.c @@ -143,10 +143,13 @@ unix_to_efi(void) char *walker; int rv; + dp = NULL; while (fgets(buffer, sizeof(buffer), stdin)) { walker= trim(buffer); + free(dp); + dp = NULL; rv = efivar_unix_path_to_device_path(walker, &dp); - if (rv != 0) { + if (rv != 0 || dp == NULL) { errno = rv; warn("Can't convert '%s' to efi", walker); continue; @@ -158,6 +161,7 @@ unix_to_efi(void) } printf("%s\n", efi); } + free(dp); } static void