[gnome-settings-daemon/benzea/hide-realpath-errors] power: Do not print an error for failures from realpath




commit 5eaec6f5c1b1889d4029b5b22a52806a846e5f91
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Nov 30 11:35:49 2021 +0100

    power: Do not print an error for failures from realpath
    
    Doing so leaks information about whether a file/directory exists even if
    it is outside of the /sys/class/backlight directory.
    
    Closes: #634

 plugins/power/gsd-backlight-helper.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
---
diff --git a/plugins/power/gsd-backlight-helper.c b/plugins/power/gsd-backlight-helper.c
index c370c791..f0fbbb59 100644
--- a/plugins/power/gsd-backlight-helper.c
+++ b/plugins/power/gsd-backlight-helper.c
@@ -85,13 +85,6 @@ main (int argc, char *argv[])
                goto done;
        }
 
-       device = realpath (argv[1], NULL);
-       if (device == NULL) {
-               fprintf (stderr, "Error: Could not canonicalize given path (%d: %s)\n", errno, strerror 
(errno));
-               result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
-               goto done;
-       }
-
        dp = opendir ("/sys/class/backlight");
        if (dp == NULL) {
                fprintf (stderr, "Error: Could not open /sys/class/backlight (%d: %s)\n", errno, strerror 
(errno));
@@ -99,6 +92,9 @@ main (int argc, char *argv[])
                goto done;
        }
 
+       /* May be NULL if the path cannot be resolved */
+       device = realpath (argv[1], NULL);
+
        while ((ep = readdir (dp))) {
                char *path;
 
@@ -108,7 +104,7 @@ main (int argc, char *argv[])
                /* Leave room for "/brightness" */
                snprintf (tmp, sizeof(tmp) - 11, "/sys/class/backlight/%s", ep->d_name);
                path = realpath (tmp, NULL);
-               if (strcmp (path, device) == 0) {
+               if (path && device && strcmp (path, device) == 0) {
                        free (path);
                        strcat (tmp, "/brightness");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]