* [PATCH] mtd: mkfs.ubifs: Improve error handling of is_contained()
@ 2012-10-16 11:51 Marcus Prebble
2012-10-26 13:56 ` Artem Bityutskiy
0 siblings, 1 reply; 2+ messages in thread
From: Marcus Prebble @ 2012-10-16 11:51 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 580 bytes --]
mtd: mtd-utils/mkfs.ubifs: Improve error handling of is_contained()
The is_contained() function returns -1 if an error occurs when
canonicalizing the output file path/root directory. This resulted in the
confusing error message 'Error: The output file cannot be in the UBIFS
root' when specifying a non-existent directory for the output.
This patch changes the error handling to display a different error
message for the case when is_contained() returns -1.
Additionally it frees all memory allocated by is_contained().
Signed-off-by: Marcus Prebble <marcus.prebble@axis.com>
[-- Attachment #2: 0001-mkfs.ubifs-is-contained-err-handling.patch --]
[-- Type: text/x-patch, Size: 2115 bytes --]
diff --git a/mtd-utils/mkfs.ubifs/mkfs.ubifs.c b/mtd-utils/mkfs.ubifs/mkfs.ubifs.c
index a361df9..24554de 100644
--- a/mtd-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/mtd-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -252,7 +252,10 @@ static char *make_path(const char *dir, const char *name)
*/
static int is_contained(const char *file, const char *dir)
{
- char *file_base, *copy, *real_file, *real_dir, *p;
+ char *real_file = NULL;
+ char *real_dir = NULL;
+ char *file_base, *copy;
+ int ret = -1;
/* Make a copy of the file path because 'dirname()' can modify it */
copy = strdup(file);
@@ -262,31 +265,29 @@ static int is_contained(const char *file, const char *dir)
/* Turn the paths into the canonical form */
real_file = malloc(PATH_MAX);
- if (!real_file) {
- free(copy);
- return -1;
- }
+ if (!real_file)
+ goto out_free;
real_dir = malloc(PATH_MAX);
- if (!real_dir) {
- free(real_file);
- free(copy);
- return -1;
- }
+ if (!real_dir)
+ goto out_free;
+
if (!realpath(file_base, real_file)) {
- perror("realpath");
- return -1;
+ perror("Could not canonicalize file path");
+ goto out_free;
}
if (!realpath(dir, real_dir)) {
- perror("realpath");
- return -1;
+ perror("Could not canonicalize directory");
+ goto out_free;
}
- p = strstr(real_file, real_dir);
- free(real_dir);
- free(real_file);
+ ret = !!strstr(real_file, real_dir);
+
+out_free:
free(copy);
- return !!p;
+ free(real_file);
+ free(real_dir);
+ return ret;
}
/**
@@ -346,9 +347,13 @@ static int validate_options(void)
if (!output)
return err_msg("no output file or UBI volume specified");
- if (root && is_contained(output, root))
- return err_msg("output file cannot be in the UBIFS root "
- "directory");
+ if (root) {
+ if ((tmp = is_contained(output, root)) < 0)
+ return err_msg("failed to perform output file root check");
+ else if (tmp)
+ return err_msg("output file cannot be in the UBIFS root "
+ "directory");
+ }
if (!is_power_of_2(c->min_io_size))
return err_msg("min. I/O unit size should be power of 2");
if (c->leb_size < c->min_io_size)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: mkfs.ubifs: Improve error handling of is_contained()
2012-10-16 11:51 [PATCH] mtd: mkfs.ubifs: Improve error handling of is_contained() Marcus Prebble
@ 2012-10-26 13:56 ` Artem Bityutskiy
0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2012-10-26 13:56 UTC (permalink / raw)
To: Marcus Prebble; +Cc: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
On Tue, 2012-10-16 at 13:51 +0200, Marcus Prebble wrote:
> mtd: mtd-utils/mkfs.ubifs: Improve error handling of is_contained()
>
> The is_contained() function returns -1 if an error occurs when
> canonicalizing the output file path/root directory. This resulted in the
> confusing error message 'Error: The output file cannot be in the UBIFS
> root' when specifying a non-existent directory for the output.
> This patch changes the error handling to display a different error
> message for the case when is_contained() returns -1.
> Additionally it frees all memory allocated by is_contained().
>
> Signed-off-by: Marcus Prebble <marcus.prebble@axis.com>
Pushed to mtd-utils.git, thanks!
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-26 13:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-16 11:51 [PATCH] mtd: mkfs.ubifs: Improve error handling of is_contained() Marcus Prebble
2012-10-26 13:56 ` Artem Bityutskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.