1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

linux.cc,net_stat.cc: use ${iface X} inside upspeed/f downspeed/f (#608)

* linux.cc,net_stat.cc: use ${iface X} inside upspeed/f downspeed/f

* net_stat.cc: Avoid dereferecing null pointer in parse_net_stat_arg()
This commit is contained in:
lasers 2018-08-13 13:40:30 -05:00 committed by GitHub
parent e4e6a4ff60
commit fcbc5c8ba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 6 deletions

View File

@ -100,7 +100,7 @@ char e_iface[50];
/* To use ${iface X} where X is a number and will
* return the current X NIC name */
static const unsigned int iface_len = 64U;
static char interfaces_arr[iface_len][iface_len] = {""};
char interfaces_arr[iface_len][iface_len] = {""};
#define SHORTSTAT_TEMPL "%*s %llu %llu %llu"
#define LONGSTAT_TEMPL "%*s %llu %llu %llu "
@ -441,6 +441,7 @@ void print_gateway_ip(struct text_object *obj, char *p, unsigned int p_max_size)
**/
int update_net_stats(void) {
update_gateway_info();
update_gateway_info2();
FILE *net_dev_fp;
static int rep = 0;
/* variably to notify the parts averaging the download speed, that this
@ -451,8 +452,10 @@ int update_net_stats(void) {
static char first = 1;
// FIXME: arbitrary size chosen to keep code simple.
int i, i2;
unsigned int curtmp1, curtmp2;
int i;
int i2;
unsigned int curtmp1;
unsigned int curtmp2;
unsigned int k;
struct ifconf conf;
char buf[256];

View File

@ -59,4 +59,6 @@ void print_distribution(struct text_object *, char *, unsigned int);
void determine_longstat_file(void);
extern char e_iface[50];
extern char interfaces_arr[64][64];
#endif /* _LINUX_H */

View File

@ -31,6 +31,8 @@
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <string.h>
#include <ctype.h>
#include "conky.h"
#include "logging.h"
#include "net/if.h"
@ -51,7 +53,8 @@
#if defined(__linux__)
#include "linux.h"
#else
char e_iface[50] = "empty";
static char e_iface[50] = "empty";
static char interfaces_arr[64][64] = {""};
#endif /* __linux__ */
/* network interface stuff */
@ -120,6 +123,11 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg,
char nextarg[21]; // longest arg possible is a devname (max 20 chars)
int i = 0;
struct net_stat *netstat = nullptr;
long int x = 0;
unsigned int found = 0;
char *arg_ptr = (char *)arg;
char buf[64];
char *buf_ptr = buf;
if (arg == nullptr) { arg = DEFAULTNETDEV; }
@ -128,6 +136,24 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg,
arg = e_iface;
}
if (0 == strncmp(arg, "${iface", 7)) {
if (nullptr != arg_ptr) {
for (; *arg_ptr; arg_ptr++) {
if (isdigit((unsigned char)*arg_ptr)) {
*buf_ptr++ = *arg_ptr;
found = 1;
}
}
}
if (1U == found) {
*buf_ptr = '\0';
x = strtol(buf, (char **)NULL, 10);
if (63L > x) {
arg = interfaces_arr[x];
}
}
}
while (sscanf(arg + i, " %20s", nextarg) == 1) {
if (strcmp(nextarg, "-n") == 0 || strcmp(nextarg, "--netmask") == 0) {
shownetmask = true;

View File

@ -876,7 +876,7 @@ static int get_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
}
// Perform query and print result
void print_nvidia_value(struct text_object *obj, char *p, int p_max_size) {
void print_nvidia_value(struct text_object *obj, char *p, unsigned int p_max_size) {
struct nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque);
int value, temp1, temp2;
char *str;

View File

@ -31,7 +31,7 @@
#define NVIDIA_CONKY_H
int set_nvidia_query(struct text_object *, const char *, unsigned int);
void print_nvidia_value(struct text_object *, char *, int);
void print_nvidia_value(struct text_object *, char *,unsigned int);
double get_nvidia_barval(struct text_object *);
void free_nvidia(struct text_object *);