1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
From: Philip Withnall <pwithnall@endlessos.org>
Date: Tue, 16 Mar 2021 11:36:27 +0000
Subject: glocalfileoutputstream: Tidy up error handling
After the recent reworking of this code it was possible for `g_close()`
to be called on `fd == -1`, which is invalid. It would have reported an
error, were errors not ignored. So it was harmless, but still best to
fix.
Simplify the error handling by combining both error labels and checking
the state of `fd` dynamically.
Coverity CID: #1450834
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2325
Bug-Debian: https://bugs.debian.org/984969
Origin: backport, commit:c4b4fecaef5fa6eac63569513511ba6f8674548a
Forwarded: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2002
---
gio/glocalfileoutputstream.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index fff2439..8d7eadd 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -829,7 +829,7 @@ handle_overwrite_open (const char *filename,
_("Error when getting information for file ā%sā: %s"),
display_name, g_strerror (errsv));
g_free (display_name);
- goto err_out;
+ goto error;
}
/* not a regular file */
@@ -841,7 +841,7 @@ handle_overwrite_open (const char *filename,
G_IO_ERROR,
G_IO_ERROR_IS_DIRECTORY,
_("Target file is a directory"));
- goto err_out;
+ goto error;
}
else if (!is_symlink ||
#ifdef S_ISLNK
@@ -855,7 +855,7 @@ handle_overwrite_open (const char *filename,
G_IO_ERROR,
G_IO_ERROR_NOT_REGULAR_FILE,
_("Target file is not a regular file"));
- goto err_out;
+ goto error;
}
}
@@ -869,7 +869,7 @@ handle_overwrite_open (const char *filename,
G_IO_ERROR_WRONG_ETAG,
_("The file was externally modified"));
g_free (current_etag);
- goto err_out;
+ goto error;
}
g_free (current_etag);
}
@@ -962,7 +962,7 @@ handle_overwrite_open (const char *filename,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Backup file creation failed"));
g_free (backup_filename);
- goto err_out;
+ goto error;
}
bfd = g_open (backup_filename,
@@ -976,7 +976,7 @@ handle_overwrite_open (const char *filename,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Backup file creation failed"));
g_free (backup_filename);
- goto err_out;
+ goto error;
}
/* If needed, Try to set the group of the backup same as the
@@ -993,7 +993,7 @@ handle_overwrite_open (const char *filename,
g_unlink (backup_filename);
g_close (bfd, NULL);
g_free (backup_filename);
- goto err_out;
+ goto error;
}
if ((original_stat.st_gid != tmp_statbuf.st_gid) &&
@@ -1010,7 +1010,7 @@ handle_overwrite_open (const char *filename,
g_unlink (backup_filename);
g_close (bfd, NULL);
g_free (backup_filename);
- goto err_out;
+ goto error;
}
}
#endif
@@ -1025,7 +1025,7 @@ handle_overwrite_open (const char *filename,
g_close (bfd, NULL);
g_free (backup_filename);
- goto err_out;
+ goto error;
}
g_close (bfd, NULL);
@@ -1040,7 +1040,7 @@ handle_overwrite_open (const char *filename,
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errsv));
- goto err_out;
+ goto error;
}
}
@@ -1056,7 +1056,7 @@ handle_overwrite_open (const char *filename,
g_io_error_from_errno (errsv),
_("Error removing old file: %s"),
g_strerror (errsv));
- goto err_out2;
+ goto error;
}
if (readable)
@@ -1073,7 +1073,7 @@ handle_overwrite_open (const char *filename,
_("Error opening file ā%sā: %s"),
display_name, g_strerror (errsv));
g_free (display_name);
- goto err_out2;
+ goto error;
}
}
else
@@ -1091,15 +1091,16 @@ handle_overwrite_open (const char *filename,
g_io_error_from_errno (errsv),
_("Error truncating file: %s"),
g_strerror (errsv));
- goto err_out;
+ goto error;
}
}
return fd;
- err_out:
- g_close (fd, NULL);
- err_out2:
+error:
+ if (fd >= 0)
+ g_close (fd, NULL);
+
return -1;
}
|