summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tzsetup
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>2012-01-12 05:50:32 +0000
committerwollman <wollman@FreeBSD.org>2012-01-12 05:50:32 +0000
commit240031a5631d1402bd57bc12ed8aea6a3d919a58 (patch)
treec7805128861466b97c7091eef98901435fcddd98 /usr.sbin/tzsetup
parent8e2b5cb8354e06cb2b207e8e3a55be3b81e2b9d2 (diff)
downloadFreeBSD-src-240031a5631d1402bd57bc12ed8aea6a3d919a58.zip
FreeBSD-src-240031a5631d1402bd57bc12ed8aea6a3d919a58.tar.gz
Use a reasonable-sized buffer when formatting error messages about
installing zoneinfo. While we're in the vicinity, add some missing error checking to eliminate an unhelpful error message when unlink() fails. /me is embarrassed by the quality of his 16-year-old code. The whole thing is awful and could stand a complete rewrite. PR: 164038 Submitted by: Devin Teske (but implemented differently)
Diffstat (limited to 'usr.sbin/tzsetup')
-rw-r--r--usr.sbin/tzsetup/tzsetup.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c
index 5c8c09b..52824cd 100644
--- a/usr.sbin/tzsetup/tzsetup.c
+++ b/usr.sbin/tzsetup/tzsetup.c
@@ -57,6 +57,13 @@ __FBSDID("$FreeBSD$");
#define _PATH_DB "/var/db/zoneinfo"
#define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
+#ifdef PATH_MAX
+#define SILLY_BUFFER_SIZE 2*PATH_MAX
+#else
+#warning "Somebody needs to fix this to dynamically size this buffer."
+#define SILLY_BUFFER_SIZE 2048
+#endif
+
/* special return codes for `fire' actions */
#define DITEM_FAILURE 1
@@ -638,7 +645,7 @@ static int
install_zoneinfo_file(const char *zoneinfo_file)
{
char buf[1024];
- char title[64], prompt[64];
+ char title[64], prompt[SILLY_BUFFER_SIZE];
struct stat sb;
ssize_t len;
int fd1, fd2, copymode;
@@ -709,7 +716,18 @@ install_zoneinfo_file(const char *zoneinfo_file)
return (DITEM_FAILURE | DITEM_RECREATE);
}
- unlink(path_localtime);
+ if (unlink(path_localtime) < 0) {
+ snprintf(prompt, sizeof(prompt),
+ "Could not unlink %s: %s",
+ path_localtime, strerror(errno));
+ if (usedialog) {
+ snprintf(title, sizeof(title), "Error");
+ dialog_msgbox(title, prompt, 8, 72, 1);
+ } else
+ fprintf(stderr, "%s\n", prompt);
+ return (DITEM_FAILURE | DITEM_RECREATE);
+ }
+
fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IRGRP | S_IROTH);
if (fd2 < 0) {
@@ -755,7 +773,17 @@ install_zoneinfo_file(const char *zoneinfo_file)
fprintf(stderr, "%s\n", prompt);
return (DITEM_FAILURE | DITEM_RECREATE);
}
- unlink(path_localtime);
+ if (unlink(path_localtime) < 0) {
+ snprintf(prompt, sizeof(prompt),
+ "Could not unlink %s: %s",
+ path_localtime, strerror(errno));
+ if (usedialog) {
+ snprintf(title, sizeof(title), "Error");
+ dialog_msgbox(title, prompt, 8, 72, 1);
+ } else
+ fprintf(stderr, "%s\n", prompt);
+ return (DITEM_FAILURE | DITEM_RECREATE);
+ }
if (symlink(zoneinfo_file, path_localtime) < 0) {
snprintf(title, sizeof(title), "Error");
snprintf(prompt, sizeof(prompt),
OpenPOWER on IntegriCloud