mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-22 09:57:20 +00:00
[master] Fixed relative file name crash
Merges in rt46957
This commit is contained in:
parent
d394b602d4
commit
db4e4aa2e4
7
RELNOTES
7
RELNOTES
@ -103,6 +103,13 @@ by Eric Young (eay@cryptsoft.com).
|
||||
cannot rely on the results of executable statements.
|
||||
[ISC-Bugs #45451]
|
||||
|
||||
- Fixed a bug which causes dhcpd and dhclient to crash on certain
|
||||
systems when given relative path names for lease or pid files on
|
||||
the command line. Affected systems are those on which the C library
|
||||
function, realpath() does not support a second parameter value of
|
||||
NULL (see manpages for realpath(3)).
|
||||
[ISC-Bugs #46957]
|
||||
|
||||
Changes since 4.4.0a1 (New Features)
|
||||
|
||||
- Added experimental support for relay port (draft-ietf-dhc-relay-port-10.txt)
|
||||
|
@ -639,17 +639,11 @@ main(int argc, char **argv) {
|
||||
* to be reopened after chdir() has been called
|
||||
*/
|
||||
if (path_dhclient_db[0] != '/') {
|
||||
const char *old_path = path_dhclient_db;
|
||||
path_dhclient_db = realpath(path_dhclient_db, NULL);
|
||||
if (path_dhclient_db == NULL)
|
||||
log_fatal("Failed to get realpath for %s: %s", old_path, strerror(errno));
|
||||
path_dhclient_db = absolute_path(path_dhclient_db);
|
||||
}
|
||||
|
||||
if (path_dhclient_script[0] != '/') {
|
||||
const char *old_path = path_dhclient_script;
|
||||
path_dhclient_script = realpath(path_dhclient_script, NULL);
|
||||
if (path_dhclient_script == NULL)
|
||||
log_fatal("Failed to get realpath for %s: %s", old_path, strerror(errno));
|
||||
path_dhclient_script = absolute_path(path_dhclient_script);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3,7 +3,7 @@
|
||||
Turn data structures into printable text. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 2004-2018 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1995-2003 by Internet Software Consortium
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
@ -1439,3 +1439,43 @@ char *format_lease_id(const unsigned char *s, unsigned len,
|
||||
}
|
||||
return (idstr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a relative path name to an absolute path name
|
||||
*
|
||||
* Not all versions of realpath() support NULL for
|
||||
* the second parameter and PATH_MAX isn't defined
|
||||
* on all systems. For the latter, we'll make what
|
||||
* ought to be a big enough buffer and let it fly.
|
||||
* If passed an absolute path it should return it
|
||||
* an allocated buffer.
|
||||
*/
|
||||
char *absolute_path(const char *orgpath) {
|
||||
char *abspath = NULL;
|
||||
if (orgpath) {
|
||||
#ifdef PATH_MAX
|
||||
char buf[PATH_MAX];
|
||||
#else
|
||||
char buf[2048];
|
||||
int len;
|
||||
#endif
|
||||
errno = 0;
|
||||
if (realpath(orgpath, buf) == NULL) {
|
||||
const char* errmsg = strerror(errno);
|
||||
log_fatal("Failed to get realpath for %s: %s",
|
||||
orgpath, errmsg);
|
||||
}
|
||||
|
||||
/* dup the result into an allocated buffer */
|
||||
abspath = dmalloc(strlen(buf) + 1, MDL);
|
||||
if (abspath == NULL) {
|
||||
log_fatal("No memory for filename:%s\n",
|
||||
buf);
|
||||
}
|
||||
|
||||
memcpy (abspath, buf, strlen(buf));
|
||||
abspath[strlen(buf)] = 0x0;
|
||||
}
|
||||
|
||||
return (abspath);
|
||||
}
|
||||
|
@ -2635,6 +2635,7 @@ char *buf_to_hex (const unsigned char *s, unsigned len,
|
||||
const char *file, int line);
|
||||
char *format_lease_id(const unsigned char *s, unsigned len, int format,
|
||||
const char *file, int line);
|
||||
char *absolute_path(const char *orgpath);
|
||||
/* socket.c */
|
||||
#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
|
||||
|| defined (USE_SOCKET_FALLBACK)
|
||||
|
@ -607,11 +607,7 @@ main(int argc, char **argv) {
|
||||
* to be reopened after chdir() has been called
|
||||
*/
|
||||
if (have_dhcpd_db && path_dhcpd_db[0] != '/') {
|
||||
const char *path = path_dhcpd_db;
|
||||
path_dhcpd_db = realpath(path_dhcpd_db, NULL);
|
||||
if (path_dhcpd_db == NULL)
|
||||
log_fatal("Failed to get realpath for %s: %s", path,
|
||||
strerror(errno));
|
||||
path_dhcpd_db = absolute_path(path_dhcpd_db);
|
||||
}
|
||||
|
||||
if (!quiet) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user