Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F102667931
D44572.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D44572.diff
View Options
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -113,8 +113,10 @@
static void
write_nextboot(const char *fn, const char *env, bool force)
{
+ char tmp[PATH_MAX];
FILE *fp;
struct statfs sfs;
+ int tmpfd;
bool supported = false;
bool zfs = false;
@@ -138,21 +140,39 @@
zfsbootcfg(sfs.f_mntfromname, force);
}
- fp = fopen(fn, "w");
+ if (strlcpy(tmp, fn, sizeof(tmp)) >= sizeof(tmp))
+ E("Path too long %s", fn);
+ if (strlcat(tmp, ".XXXXXX", sizeof(tmp)) >= sizeof(tmp))
+ E("Path too long %s", fn);
+ tmpfd = mkstemp(tmp);
+ if (tmpfd == -1)
+ E("mkstemp %s", tmp);
+
+ fp = fdopen(tmpfd, "w");
if (fp == NULL)
- E("Can't create %s", fn);
+ E("fdopen %s", tmp);
- if (fprintf(fp,"%s%s",
+ if (fprintf(fp, "%s%s",
supported ? "nextboot_enable=\"YES\"\n" : "",
env != NULL ? env : "") < 0) {
int e;
e = errno;
- fclose(fp);
- if (unlink(fn))
- warn("unlink %s", fn);
+ if (unlink(tmp))
+ warn("unlink %s", tmp);
+ errno = e;
+ E("Can't write %s", tmp);
+ }
+ if (fsync(fileno(fp)) != 0)
+ E("Can't fsync %s", fn);
+ if (rename(tmp, fn) != 0) {
+ int e;
+
+ e = errno;
+ if (unlink(tmp))
+ warn("unlink %s", tmp);
errno = e;
- E("Can't write %s", fn);
+ E("Can't rename %s to %s", tmp, fn);
}
fclose(fp);
}
@@ -194,8 +214,8 @@
/*
* Different options are valid for different programs.
*/
-#define GETOPT_REBOOT "cDde:k:lNno:pqr"
-#define GETOPT_NEXTBOOT "De:k:o:"
+#define GETOPT_REBOOT "cDde:fk:lNno:pqr"
+#define GETOPT_NEXTBOOT "De:fk:o:"
int
main(int argc, char *argv[])
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 2:42 PM (20 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14660188
Default Alt Text
D44572.diff (1 KB)
Attached To
Mode
D44572: nextboot: Write nextboot.conf safely
Attached
Detach File
Event Timeline
Log In to Comment