[PATCH 1/2] apfsck: fix year of copyright

2 views
Skip to first unread message

Ernesto A. Fernández

unread,
Mar 14, 2019, 7:53:47 PM3/14/19
to linux...@googlegroups.com
Work on this project began in 2019, but most file headers use the year
2018 for the copyright. This mistake is the result of copy-paste from
the kernel module.

Signed-off-by: Ernesto A. Fernández <ernesto.mn...@gmail.com>
---
apfsck/apfsck.c | 2 +-
apfsck/apfsck.h | 2 +-
apfsck/btree.c | 2 +-
apfsck/btree.h | 2 +-
apfsck/crc32c.h | 2 +-
apfsck/dir.c | 2 +-
apfsck/dir.h | 2 +-
apfsck/extents.c | 2 +-
apfsck/extents.h | 2 +-
apfsck/inode.c | 2 +-
apfsck/inode.h | 2 +-
apfsck/key.c | 2 +-
apfsck/key.h | 2 +-
apfsck/object.h | 2 +-
apfsck/super.c | 2 +-
apfsck/super.h | 2 +-
apfsck/types.h | 2 +-
apfsck/unicode.c | 2 +-
apfsck/unicode.h | 2 +-
apfsck/xattr.c | 2 +-
apfsck/xattr.h | 2 +-
21 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/apfsck/apfsck.c b/apfsck/apfsck.c
index bfc767b..32b7459 100644
--- a/apfsck/apfsck.c
+++ b/apfsck/apfsck.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/apfsck.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <stdarg.h>
diff --git a/apfsck/apfsck.h b/apfsck/apfsck.h
index b1b37f8..4cfb41a 100644
--- a/apfsck/apfsck.h
+++ b/apfsck/apfsck.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/apfsck.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _APFSCK_H
diff --git a/apfsck/btree.c b/apfsck/btree.c
index 419e96a..0205907 100644
--- a/apfsck/btree.c
+++ b/apfsck/btree.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/btree.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <assert.h>
diff --git a/apfsck/btree.h b/apfsck/btree.h
index 657fd55..caff828 100644
--- a/apfsck/btree.h
+++ b/apfsck/btree.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/btree.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _BTREE_H
diff --git a/apfsck/crc32c.h b/apfsck/crc32c.h
index 341adfc..93a3ead 100644
--- a/apfsck/crc32c.h
+++ b/apfsck/crc32c.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/crc32c.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _CRC32C_H
diff --git a/apfsck/dir.c b/apfsck/dir.c
index af50320..560fe82 100644
--- a/apfsck/dir.c
+++ b/apfsck/dir.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/dir.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <stdio.h>
diff --git a/apfsck/dir.h b/apfsck/dir.h
index e97f001..bf7dcb9 100644
--- a/apfsck/dir.h
+++ b/apfsck/dir.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/dir.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _DIR_H
diff --git a/apfsck/extents.c b/apfsck/extents.c
index b3f52e2..baf6c06 100644
--- a/apfsck/extents.c
+++ b/apfsck/extents.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/extents.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <stdlib.h>
diff --git a/apfsck/extents.h b/apfsck/extents.h
index db11913..69d7f0e 100644
--- a/apfsck/extents.h
+++ b/apfsck/extents.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/extents.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _EXTENTS_H
diff --git a/apfsck/inode.c b/apfsck/inode.c
index 0c0d060..5c9e6cf 100644
--- a/apfsck/inode.c
+++ b/apfsck/inode.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/inode.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <assert.h>
diff --git a/apfsck/inode.h b/apfsck/inode.h
index 292c5ed..95a6783 100644
--- a/apfsck/inode.h
+++ b/apfsck/inode.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/inode.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _INODE_H
diff --git a/apfsck/key.c b/apfsck/key.c
index 20d394e..0d7b290 100644
--- a/apfsck/key.c
+++ b/apfsck/key.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/key.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <stdio.h>
diff --git a/apfsck/key.h b/apfsck/key.h
index fa550ea..211b385 100644
--- a/apfsck/key.h
+++ b/apfsck/key.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/key.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _KEY_H
diff --git a/apfsck/object.h b/apfsck/object.h
index 0691e53..1c90656 100644
--- a/apfsck/object.h
+++ b/apfsck/object.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/object.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _OBJECT_H
diff --git a/apfsck/super.c b/apfsck/super.c
index 6bfdb5a..aba654f 100644
--- a/apfsck/super.c
+++ b/apfsck/super.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/super.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <stdio.h>
diff --git a/apfsck/super.h b/apfsck/super.h
index b69257c..26b332f 100644
--- a/apfsck/super.h
+++ b/apfsck/super.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/super.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _SUPER_H
diff --git a/apfsck/types.h b/apfsck/types.h
index 59c2047..5166123 100644
--- a/apfsck/types.h
+++ b/apfsck/types.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/types.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*
* Definitions that make it easier to reuse code from the kernel module.
*/
diff --git a/apfsck/unicode.c b/apfsck/unicode.c
index 61abde4..8e1430c 100644
--- a/apfsck/unicode.c
+++ b/apfsck/unicode.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/unicode.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*
* Routines and data for the normalization of unicode strings.
* Somewhat based on linux/fs/hfsplus/unicode.c
diff --git a/apfsck/unicode.h b/apfsck/unicode.h
index 0072775..c0360d9 100644
--- a/apfsck/unicode.h
+++ b/apfsck/unicode.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/unicode.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _UNICODE_H
diff --git a/apfsck/xattr.c b/apfsck/xattr.c
index 07bb207..bf4d0a1 100644
--- a/apfsck/xattr.c
+++ b/apfsck/xattr.c
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/xattr.c
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#include <string.h>
diff --git a/apfsck/xattr.h b/apfsck/xattr.h
index 125ecdd..83580eb 100644
--- a/apfsck/xattr.h
+++ b/apfsck/xattr.h
@@ -1,7 +1,7 @@
/*
* apfsprogs/apfsck/xattr.h
*
- * Copyright (C) 2018 Ernesto A. Fernández <ernesto.mn...@gmail.com>
+ * Copyright (C) 2019 Ernesto A. Fernández <ernesto.mn...@gmail.com>
*/

#ifndef _XATTR_H
--
2.11.0

Ernesto A. Fernández

unread,
Mar 14, 2019, 7:54:03 PM3/14/19
to linux...@googlegroups.com
When parse_subtree() is done with a node, it should release it with
free_node() instead of just free(). Otherwise the associated free space
bitmaps will leak, and the physical block will remain mapped.

I have been aware of this issue for a while, but memory leaks are not
particularly urgent for a program that will only run for a few minutes
at a time. There are still many structures I don't even attempt to
free. Much of this will need to be improved when we start parsing old
checkpoints.

Since in-memory catalog keys could point to memory-mapped on-disk names,
make sure they are copied into a memory buffer before releasing their
node. I'm not entirely pleased with this, but I can't think of a
cleaner solution without a big rewrite.

Fixes: a71899fe1353 ("apfsck: check order of keys in the container omap")
Signed-off-by: Ernesto A. Fernández <ernesto.mn...@gmail.com>
---
apfsck/btree.c | 24 +++++++++++++++++++-----
apfsck/key.c | 12 ++++++++++++
2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/apfsck/btree.c b/apfsck/btree.c
index 0205907..a0a588d 100644
--- a/apfsck/btree.c
+++ b/apfsck/btree.c
@@ -527,8 +527,11 @@ static void parse_cat_record(void *key, void *val, int len)
* @last_key: parent key, that must come before all the keys in this subtree;
* on return, this will hold the last key of this subtree, that
* must come before the next key of the parent node
+ * @name_buf: buffer to store the name of @last_key when its node is freed
+ * (can be NULL if the keys have no name)
*/
-static void parse_subtree(struct node *root, struct key *last_key)
+static void parse_subtree(struct node *root,
+ struct key *last_key, char *name_buf)
{
struct btree *btree = root->btree;
struct key curr_key;
@@ -606,12 +609,22 @@ static void parse_subtree(struct node *root, struct key *last_key)
report("Object map",
"xid of node is older than xid of its child.");

- parse_subtree(child, last_key);
- free(child);
+ parse_subtree(child, last_key, name_buf);
+ node_free(child);
}

/* All records of @root are processed, so it's a good time for this */
node_compare_bmaps(root);
+
+ /*
+ * last_key->name is just a pointer to the memory-mapped on-disk name
+ * of the key. Since the caller will free the node, make a copy.
+ */
+ if (node_is_leaf(root) && last_key->name) {
+ assert(name_buf);
+ strcpy(name_buf, last_key->name);
+ last_key->name = name_buf;
+ }
}

/**
@@ -679,6 +692,7 @@ struct btree *parse_cat_btree(u64 oid, struct node *omap_root)
{
struct btree *cat;
struct key last_key = {0};
+ char name_buf[256];

cat = calloc(1, sizeof(*cat));
if (!cat) {
@@ -689,7 +703,7 @@ struct btree *parse_cat_btree(u64 oid, struct node *omap_root)
cat->omap_root = omap_root;
cat->root = read_node(oid, cat);

- parse_subtree(cat->root, &last_key);
+ parse_subtree(cat->root, &last_key, name_buf);

check_btree_footer(cat);
return cat;
@@ -723,7 +737,7 @@ struct btree *parse_omap_btree(u64 oid)
omap->omap_root = NULL; /* The omap doesn't have an omap of its own */
omap->root = read_node(le64_to_cpu(raw->om_tree_oid), omap);

- parse_subtree(omap->root, &last_key);
+ parse_subtree(omap->root, &last_key, NULL /* name_buf */);

check_btree_footer(omap);
return omap;
diff --git a/apfsck/key.c b/apfsck/key.c
index 0d7b290..25865eb 100644
--- a/apfsck/key.c
+++ b/apfsck/key.c
@@ -111,6 +111,10 @@ static void read_dir_rec_key(void *raw, int size, struct key *key)
report("Directory record", "filename hash is corrupted.");

namelen = le32_to_cpu(raw_key->name_len_and_hash) & 0x3FFU;
+ if (namelen > 256) {
+ /* The name must fit in name_buf from parse_subtree() */
+ report("Directory record", "name is too long.");
+ }
if (strlen(key->name) + 1 != namelen) {
/* APFS counts the NULL termination for the filename length */
report("Directory record", "wrong name length in key.");
@@ -142,6 +146,10 @@ static void read_xattr_key(void *raw, int size, struct key *key)
key->name = (char *)raw_key->name;

namelen = le16_to_cpu(raw_key->name_len);
+ if (namelen > 256) {
+ /* The name must fit in name_buf from parse_subtree() */
+ report("Xattr record", "name is too long.");
+ }
if (strlen(key->name) + 1 != namelen) {
/* APFS counts the NULL termination in the string length */
report("Xattr record", "wrong name length.");
@@ -176,6 +184,10 @@ static void read_snap_name_key(void *raw, int size, struct key *key)
key->name = (char *)raw_key->name;

namelen = le16_to_cpu(raw_key->name_len);
+ if (namelen > 256) {
+ /* The name must fit in name_buf from parse_subtree() */
+ report("Snapshot name record", "name is too long.");
+ }
if (strlen(key->name) + 1 != namelen) {
/* APFS counts the NULL termination in the string length */
report("Snapshot name record", "wrong name length.");
--
2.11.0

Reply all
Reply to author
Forward
0 new messages