fix(network): initialize all fields

Some fields were previously uninitialized (e.g. carrier), which
could lead to UB.
This commit is contained in:
peelz
2025-07-03 16:35:18 -04:00
parent 2dfbaabf31
commit b02694caef
2 changed files with 23 additions and 41 deletions

View File

@ -27,8 +27,8 @@ class Network : public ALabel {
auto update() -> void override; auto update() -> void override;
private: private:
static const uint8_t MAX_RETRY = 5; static const uint8_t MAX_RETRY{5};
static const uint8_t EPOLL_MAX = 200; static const uint8_t EPOLL_MAX{200};
static int handleEvents(struct nl_msg*, void*); static int handleEvents(struct nl_msg*, void*);
static int handleEventsDone(struct nl_msg*, void*); static int handleEventsDone(struct nl_msg*, void*);
@ -51,37 +51,37 @@ class Network : public ALabel {
bool wildcardMatch(const std::string& pattern, const std::string& text) const; bool wildcardMatch(const std::string& pattern, const std::string& text) const;
std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage(); std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage();
int ifid_; int ifid_{-1};
ip_addr_pref addr_pref_; ip_addr_pref addr_pref_{ip_addr_pref::IPV4};
struct sockaddr_nl nladdr_ = {0}; struct sockaddr_nl nladdr_{0};
struct nl_sock* sock_ = nullptr; struct nl_sock* sock_{nullptr};
struct nl_sock* ev_sock_ = nullptr; struct nl_sock* ev_sock_{nullptr};
int efd_; int efd_{-1};
int ev_fd_; int ev_fd_{-1};
int nl80211_id_; int nl80211_id_{-1};
std::mutex mutex_; std::mutex mutex_;
bool want_route_dump_; bool want_route_dump_{false};
bool want_link_dump_; bool want_link_dump_{false};
bool want_addr_dump_; bool want_addr_dump_{false};
bool dump_in_progress_; bool dump_in_progress_{false};
bool is_p2p_; bool is_p2p_{false};
unsigned long long bandwidth_down_total_; unsigned long long bandwidth_down_total_{0};
unsigned long long bandwidth_up_total_; unsigned long long bandwidth_up_total_{0};
std::string state_; std::string state_;
std::string essid_; std::string essid_;
std::string bssid_; std::string bssid_;
bool carrier_; bool carrier_{false};
std::string ifname_; std::string ifname_;
std::string ipaddr_; std::string ipaddr_;
std::string ipaddr6_; std::string ipaddr6_;
std::string gwaddr_; std::string gwaddr_;
std::string netmask_; std::string netmask_;
std::string netmask6_; std::string netmask6_;
int cidr_; int cidr_{0};
int cidr6_; int cidr6_{0};
int32_t signal_strength_dbm_; int32_t signal_strength_dbm_;
uint8_t signal_strength_; uint8_t signal_strength_;
std::string signal_strength_app_; std::string signal_strength_app_;
@ -90,9 +90,9 @@ class Network : public ALabel {
util::SleeperThread thread_; util::SleeperThread thread_;
util::SleeperThread thread_timer_; util::SleeperThread thread_timer_;
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
util::Rfkill rfkill_; util::Rfkill rfkill_{RFKILL_TYPE_WLAN};
#endif #endif
float frequency_; float frequency_{0};
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -78,25 +78,7 @@ waybar::modules::Network::readBandwidthUsage() {
} }
waybar::modules::Network::Network(const std::string &id, const Json::Value &config) waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
: ALabel(config, "network", id, DEFAULT_FORMAT, 60), : ALabel(config, "network", id, DEFAULT_FORMAT, 60) {
ifid_(-1),
addr_pref_(IPV4),
efd_(-1),
ev_fd_(-1),
want_route_dump_(false),
want_link_dump_(false),
want_addr_dump_(false),
dump_in_progress_(false),
is_p2p_(false),
cidr_(0),
cidr6_(0),
signal_strength_dbm_(0),
signal_strength_(0),
#ifdef WANT_RFKILL
rfkill_{RFKILL_TYPE_WLAN},
#endif
frequency_(0.0) {
// Start with some "text" in the module's label_. update() will then // Start with some "text" in the module's label_. update() will then
// update it. Since the text should be different, update() will be able // update it. Since the text should be different, update() will be able
// to show or hide the event_box_. This is to work around the case where // to show or hide the event_box_. This is to work around the case where