Skip to contentSkip to conversation

ubifs: do not decide upon uninitialized variable

PATCH New Heinrich Schuchardt 3 participants 5 messages Dec 25, 2020 – Jan 20, 2021 UBI file system (UBIFS)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: do not decide upon uninitialized variable

Before 'if (err)' we have to initialize the variable otherwise we use a random value from the stack.

---
 fs/ubifs/io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/io.c +4 -4
index eb14b89544..9962cbe7eb 100644
@@ -114,7 +114,7 @@ int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
 int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
 		    int len)
 {
-	int err;
+	int err = 0;
 
 	ubifs_assert(!c->ro_media && !c->ro_mount);
 	if (c->ro_error)
@@ -136,7 +136,7 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
 
 int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
 {
-	int err;
+	int err = 0;
 
 	ubifs_assert(!c->ro_media && !c->ro_mount);
 	if (c->ro_error)
@@ -158,7 +158,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
 
 int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 {
-	int err;
+	int err = 0;
 
 	ubifs_assert(!c->ro_media && !c->ro_mount);
 	if (c->ro_error)
@@ -179,7 +179,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 
 int ubifs_leb_map(struct ubifs_info *c, int lnum)
 {
-	int err;
+	int err = 0;
 
 	ubifs_assert(!c->ro_media && !c->ro_mount);
 	if (c->ro_error)

--
2.29.2

#1 lore raw

PATCH 1/1 ubifs: do not decide upon uninitialized variable

(note replying on mobile device only code access is via git.denx.de)

Quoted 6 lines · Heinrich Schuchardt,

Before 'if (err)' we have to initialize the variable otherwise we use a random value from the stack.

---

In all the cases below err might be uninitialised because the code that would otherwise initialise it has been conditionally excluded with #ifndef __UBOOT__. I wonder if we could do something cleaner by making dbg_leb_change() etc do something suitable (return 0 or -Esomething).

 fs/ubifs/io.c | 8 ++++----
Quoted 51 lines
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/io.c +1 -1
index eb14b89544..9962cbe7eb 100644
@@ -114,7 +114,7 @@ int ubifs_leb_read(const struct ubifs_info *c, int
 lnum, void *buf, int offs,
 int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int
 offs,
                    int len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +1 -1
@@ -136,7 +136,7 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum,
 const void *buf, int offs,
 
 int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int
 len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +1 -1
@@ -158,7 +158,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum,
 const void *buf, int len)
 
 int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +1 -2
@@ -179,7 +179,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 
 int ubifs_leb_map(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
--

2.29.2

#2 lore raw

PATCH 1/1 ubifs: do not decide upon uninitialized variable

Am 26. Dezember 2020 08:08:52 MEZ schrieb Chris Packham <[email protected]>:

Quoted 13 lines

(note replying on mobile device only code access is via git.denx.de)

Quoted 1 line · Heinrich Schuchardt,

Before 'if (err)' we have to initialize the variable otherwise we use

a

Quoted 5 lines

random value from the stack.

---

Quoted 5 lines

In all the cases below err might be uninitialised because the code that would otherwise initialise it has been conditionally excluded with #ifndef
__UBOOT__. I wonder if we could do something cleaner by making dbg_leb_change() etc do something suitable (return 0 or -Esomething).

Why would that be cleaner?

Best regards

Heinrich

Quoted 59 lines

fs/ubifs/io.c | 8 ++++----

fs/ubifs/io.c int ubifs_leb_read(const struct ubifs_info *c,

Quoted 7 lines
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/io.c +0 -0
index eb14b89544..9962cbe7eb 100644
@@ -114,7 +114,7 @@ int ubifs_leb_read(const struct ubifs_info *c,

int

fs/ubifs/io.c int ubifs_leb_read(const struct ubifs_info *c, · line 115

Quoted 2 lines
fs/ubifs/io.c +0 -0
 lnum, void *buf, int offs,
 int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf,

int

fs/ubifs/io.c int ubifs_leb_write(struct ubifs_info *c, int

Quoted 9 lines
fs/ubifs/io.c +1 -1
 offs,
                    int len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -136,7 +136,7 @@ int ubifs_leb_write(struct ubifs_info *c, int

lnum,

fs/ubifs/io.c int ubifs_leb_write(struct ubifs_info *c, int · line 138

Quoted 3 lines
fs/ubifs/io.c +0 -0
 const void *buf, int offs,
 
 int ubifs_leb_change(struct ubifs_info *c, int lnum, const void

*buf, int

fs/ubifs/io.c int ubifs_leb_change(struct ubifs_info *c, int

Quoted 8 lines
fs/ubifs/io.c +1 -1
 len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -158,7 +158,7 @@ int ubifs_leb_change(struct ubifs_info *c, int

lnum,

fs/ubifs/io.c int ubifs_leb_unmap(struct ubifs_info *c, int

Quoted 10 lines
fs/ubifs/io.c +1 -1
 const void *buf, int len)
 
 int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -179,7 +179,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int

lnum)

Quoted 12 lines
fs/ubifs/io.c +1 -2
 int ubifs_leb_map(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
--

2.29.2

#3 lore raw

PATCH 1/1 ubifs: do not decide upon uninitialized variable

Quoted 15 lines · Heinrich Schuchardt,

Am 26. Dezember 2020 08:08:52 MEZ schrieb Chris Packham < judge.packham at gmail.com>:

Quoted 13 lines

(note replying on mobile device only code access is via git.denx.de)

Quoted 1 line · Heinrich Schuchardt,

Before 'if (err)' we have to initialize the variable otherwise we use

a

Quoted 5 lines

random value from the stack.

---

Quoted 8 lines
Quoted 5 lines

In all the cases below err might be uninitialised because the code that would otherwise initialise it has been conditionally excluded with #ifndef
__UBOOT__. I wonder if we could do something cleaner by making dbg_leb_change() etc do something suitable (return 0 or -Esomething).

Why would that be cleaner?

It would keep the deviations to the upstream UBIFS code to a minimum. It's not too hard to ignore the '= 0' when syncing with upstream but it'd also be easy to miss and we'd have to redo this patch. Of course this is all hypothetical and my opinion carries little weight so I'm more than happy to be ignored if Tom wants to apply this as is.

Quoted 66 lines

Best regards

Heinrich

Quoted 59 lines

fs/ubifs/io.c | 8 ++++----

fs/ubifs/io.c int ubifs_leb_read(const struct ubifs_info *c,

Quoted 7 lines
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/io.c +0 -0
index eb14b89544..9962cbe7eb 100644
@@ -114,7 +114,7 @@ int ubifs_leb_read(const struct ubifs_info *c,

int

fs/ubifs/io.c int ubifs_leb_read(const struct ubifs_info *c, · line 115

Quoted 2 lines
fs/ubifs/io.c +0 -0
 lnum, void *buf, int offs,
 int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf,

int

fs/ubifs/io.c int ubifs_leb_write(struct ubifs_info *c, int

Quoted 9 lines
fs/ubifs/io.c +1 -1
 offs,
                    int len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -136,7 +136,7 @@ int ubifs_leb_write(struct ubifs_info *c, int

lnum,

fs/ubifs/io.c int ubifs_leb_write(struct ubifs_info *c, int · line 138

Quoted 3 lines
fs/ubifs/io.c +0 -0
 const void *buf, int offs,
 
 int ubifs_leb_change(struct ubifs_info *c, int lnum, const void

*buf, int

fs/ubifs/io.c int ubifs_leb_change(struct ubifs_info *c, int

Quoted 8 lines
fs/ubifs/io.c +1 -1
 len)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -158,7 +158,7 @@ int ubifs_leb_change(struct ubifs_info *c, int

lnum,

fs/ubifs/io.c int ubifs_leb_unmap(struct ubifs_info *c, int

Quoted 10 lines
fs/ubifs/io.c +1 -1
 const void *buf, int len)
 
 int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
fs/ubifs/io.c +0 -0
@@ -179,7 +179,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int

lnum)

Quoted 12 lines
fs/ubifs/io.c +1 -2
 int ubifs_leb_map(struct ubifs_info *c, int lnum)
 {
-       int err;
+       int err = 0;
 
        ubifs_assert(!c->ro_media && !c->ro_mount);
        if (c->ro_error)
--

2.29.2

#4 lore raw

PATCH 1/1 ubifs: do not decide upon uninitialized variable

In reply to Heinrich Schuchardt
Quoted 4 lines · Heinrich Schuchardt

Before 'if (err)' we have to initialize the variable otherwise we use a random value from the stack.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210120/f67d0eed/attachment.sig>