void rescue_timers(void);
void safe_evtimer_add(struct event *ev, struct timeval *tv);
+/* log truncated strings */
+#define safe_strcpy(dst, src, dstlen) do { \
+ size_t needed = strlcpy(dst, src, dstlen); \
+ if (unlikely(needed >= (dstlen))) \
+ log_warning("bug in %s:%d - string truncated", __FILE__, __LINE__); \
+} while (0)
+
"pkt_avail", "send_avail");
}
-static void adr2txt(const PgAddr *adr, char *dst, int dstlen)
+static void adr2txt(const PgAddr *adr, char *dst, unsigned dstlen)
{
if (adr->is_unix) {
- strlcpy(dst, "unix", dstlen);
+ safe_strcpy(dst, "unix", dstlen);
} else {
char *tmp = inet_ntoa(adr->ip_addr);
- strlcpy(dst, tmp, dstlen);
+ safe_strcpy(dst, tmp, dstlen);
}
}
db->addr.port = v_port;
db->addr.ip_addr.s_addr = v_addr;
db->addr.is_unix = host ? 0 : 1;
- strlcpy(db->unix_socket_dir, unix_dir, sizeof(db->unix_socket_dir));
+ safe_strcpy(db->unix_socket_dir, unix_dir, sizeof(db->unix_socket_dir));
if (host)
log_debug("%s: host=%s/%s", name, host, inet_ntoa(db->addr.ip_addr));
return NULL;
list_init(&db->head);
- strlcpy(db->name, name, sizeof(db->name));
+ safe_strcpy(db->name, name, sizeof(db->name));
put_in_order(&db->head, &database_list, cmp_database);
}
list_init(&user->head);
list_init(&user->pool_list);
- strlcpy(user->name, name, sizeof(user->name));
+ safe_strcpy(user->name, name, sizeof(user->name));
put_in_order(&user->head, &user_list, cmp_user);
tree_insert(&user_tree, (long)user->name, &user->tree_node);
}
- strlcpy(user->passwd, passwd, sizeof(user->passwd));
+ safe_strcpy(user->passwd, passwd, sizeof(user->passwd));
return user;
}
list_init(&user->head);
list_init(&user->pool_list);
}
- strlcpy(user->name, name, sizeof(user->name));
- strlcpy(user->passwd, passwd, sizeof(user->passwd));
+ safe_strcpy(user->name, name, sizeof(user->name));
+ safe_strcpy(user->passwd, passwd, sizeof(user->passwd));
db->forced_user = user;
return user;
}
list_init(&cache->head);
statlist_init(&cache->freelist, name);
statlist_init(&cache->slablist, name);
- strlcpy(cache->name, name, sizeof(cache->name));
+ safe_strcpy(cache->name, name, sizeof(cache->name));
cache->total_count = 0;
cache->init_func = init_func;
statlist_append(&cache->head, &objcache_list);
srcval = get_value(src, lk);
dstval = get_value(&dst->vars, lk);
if (!*dstval)
- strlcpy(dstval, srcval, lk->len);
+ memcpy(dstval, srcval, lk->len);
}
}