From 9bcfea2a892de55e71f530472bef9b403f034edb Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 20 Jul 2015 10:42:40 -0400 Subject: [PATCH 1/2] util: avoid off-by-one on long symlinks readlink does not nul terminate its result, therefore one extra byte has to be taken into account. Signed-off-by: Tobias Stoeckmann Signed-off-by: Theodore Ts'o --- util/symlinks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/symlinks.c b/util/symlinks.c index abb33f8b..3acebe7a 100644 --- a/util/symlinks.c +++ b/util/symlinks.c @@ -166,7 +166,7 @@ static void fix_symlink (char *path, dev_t my_dev) struct stat stbuf, lstbuf; int c, fix_abs = 0, fix_messy = 0, fix_long = 0; - if ((c = readlink(path, lpath, sizeof(lpath))) == -1) { + if ((c = readlink(path, lpath, sizeof(lpath) - 1)) == -1) { perror(path); return; } From 9f8d9a2c5fb8443b41183545c682189d8743923c Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 20 Jul 2015 10:52:28 -0400 Subject: [PATCH 2/2] debugfs: handle out of memory condition If malloc fails, properly handle the error condition. Signed-off-by: Tobias Stoeckmann Signed-off-by: Theodore Ts'o --- debugfs/extent_inode.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debugfs/extent_inode.c b/debugfs/extent_inode.c index 8b22f5e3..c7a92a76 100644 --- a/debugfs/extent_inode.c +++ b/debugfs/extent_inode.c @@ -97,6 +97,11 @@ void do_extent_open(int argc, char *argv[]) orig_prompt = ss_get_prompt(sci_idx); extent_prompt = malloc(strlen(orig_prompt) + 32); + if (extent_prompt == NULL) { + com_err(argv[1], retval, "out of memory"); + return; + } + strcpy(extent_prompt, orig_prompt); cp = strchr(extent_prompt, ':'); if (cp)