#include <netdb.h>
#include <errno.h>
#include <string.h>
-#include <assert.h>
#include <unistd.h>
#include <net/if.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include "ifconf.h"
+#include "macro.h"
+#include "util.h"
+
+/* Ensure that glibc's assert is used. We cannot use assert from macro.h, as
+ * libnss_myhostname will be linked into arbitrary programs which will, in turn
+ * attempt to write to the journal via log_dispatch() */
+#include <assert.h>
/* We use 127.0.0.2 as IPv4 address. This has the advantage over
* 127.0.0.1 that it can be translated back to the local hostname. For
#define LOCALADDRESS_IPV6 &in6addr_loopback
#define LOOPBACK_INTERFACE "lo"
-#define ALIGN(a) (((a+sizeof(void*)-1)/sizeof(void*))*sizeof(void*))
-
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
int32_t *ttlp) {
unsigned lo_ifi;
- char hn[HOST_NAME_MAX+1];
+ char hn[HOST_NAME_MAX+1] = {};
size_t l, idx, ms;
char *r_name;
struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;
struct address *addresses = NULL, *a;
unsigned n_addresses = 0, n;
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;
int32_t *ttlp,
char **canonp) {
- char hn[HOST_NAME_MAX+1];
+ char hn[HOST_NAME_MAX+1] = {};
if (af == AF_UNSPEC)
af = AF_INET;
return NSS_STATUS_UNAVAIL;
}
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;
int *errnop, int *h_errnop,
int32_t *ttlp) {
- char hn[HOST_NAME_MAX+1];
- struct address *addresses = NULL, *a;
+ char hn[HOST_NAME_MAX+1] = {};
+ _cleanup_free_ struct address *addresses = NULL;
+ struct address *a;
unsigned n_addresses = 0, n;
if (len != PROTO_ADDRESS_SIZE(af)) {
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
- free(addresses);
return NSS_STATUS_NOTFOUND;
found:
- free(addresses);
-
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;