Skip to contentSkip to conversation

libselinux: Add missing errno setup

PATCH Superseded Richard Filo 3 participants 7 messages Apr 6, 2020 – May 6, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: Add missing errno setup

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +2 -0
index 300625c2..113bb9b7 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
 			goto finish;
 		}
 	}
+	if (result && !result[0]) 
+		errno = ENOENT;
 
 finish:
 	free(clean_key);
Signature · 1 line
2.25.2
#1 lore raw

Hi,

Quoted 4 lines · Richard Filo

Errno is not set to ENOENT when lookup_all() doesn't find any match.

Please put the issue link after the explanation (the link is just additional information).

Also, you need to add a "Signed-off-by:" line to the end of the commit message (for legal reasons), see:
https://github.com/SELinuxProject/selinux/blob/master/CONTRIBUTING.md#contributing-code
https://opensource.com/article/18/3/cla-vs-dco-whats-difference

libselinux/src/label_file.c static const struct spec **lookup_all(struct selabel_handle *rec, · line 951

Quoted 13 lines
---
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +1 -0
index 300625c2..113bb9b7 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
                        goto finish;
                }
        }
+       if (result && !result[0])

'result' can never be NULL here, so you can drop the first part of the check.

Quoted 7 lines
libselinux/src/label_file.c +1 -1
+               errno = ENOENT;
 
 finish:
        free(clean_key);
--

2.25.2

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.

#2 lore raw

PATCH v2 1/1 libselinux: Add missing errno setup

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +2 -0
index 300625c2..113bb9b7 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
 			goto finish;
 		}
 	}
+	if (result && !result[0]) 
+		errno = ENOENT;
 
 finish:
 	free(clean_key);
Signature · 1 line
2.25.2
#3 lore raw
Quoted 14 lines · Richard Filo

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +0 -0
index 300625c2..113bb9b7 100644

libselinux/src/label_file.c static const struct spec **lookup_all(struct selabel_handle *rec, · line 952

Quoted 5 lines
libselinux/src/label_file.c +2 -0
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
                        goto finish;
                }
        }
+       if (result && !result[0])
+               errno = ENOENT;

Sorry for not spotting this earlier, but there is no need to check if result != NULL, because it will always be non-NULL at this point. So you should only do the second part of the check (!result[0]). The check under the "finish" label needs to check both, because you can get there also via the allocation-failed path, where "result" would be NULL.

Quoted 6 lines
libselinux/src/label_file.c +0 -1
 finish:
        free(clean_key);
--

2.25.2

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#4 lore raw

PATCH v3 1/1 libselinux: Add missing errno setup

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---

	-removed check: result != NULL
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +2 -0
index 300625c2..74d2027e 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
 			goto finish;
 		}
 	}
+	if (!result[0]) 
+		errno = ENOENT;
 
 finish:
 	free(clean_key);
Signature · 1 line
2.25.2
Acked-by on v3 1/1
#5 lore raw
Quoted 25 lines · Richard Filo

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---

        -removed check: result != NULL
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +2 -1
index 300625c2..74d2027e 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
                        goto finish;
                }
        }
+       if (!result[0])
+               errno = ENOENT;
 
 finish:
        free(clean_key);
--
Quoted 1 line

2.25.2

Thanks!

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#6 lore raw
Quoted 23 lines · Ondrej Mosnacek
Quoted 22 lines · Richard Filo

Errno is not set to ENOENT when lookup_all() doesn't find any match.

---

        -removed check: result != NULL
 libselinux/src/label_file.c | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.c +2 -0
index 300625c2..74d2027e 100644
@@ -948,6 +948,8 @@ static const struct spec **lookup_all(struct selabel_handle *rec,
                        goto finish;
                }
        }
+       if (!result[0])
+               errno = ENOENT;
 
Quoted 9 lines
Quoted 4 lines
libselinux/src/label_file.c +0 -1
 finish:
        free(clean_key);
--

2.25.2

Thanks!

^&^ git am v3-libselinux-Add-missing-errno-setup.patch
Applying: libselinux: Add missing errno setup .git/rebase-apply/patch:15: trailing whitespace.

        if (!result[0]) 

warning: 1 line adds whitespace errors.

I have fixed the trailing whitespace and applied it.

Thanks.