1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

Fix problems found when fixing docker (#575)

* Require at least glib-2.36 (from 03/2013) to remove deprecated g_type_init()

* Fix empty continuation line in Dockerfile

* Require at least libmicrohttpd 0.9.25 (from 09/2012) to replace deprecated MHD_create_response_from_data()

* fix versioncheck libmicrohttpd

* Missing char for null-terminator in print_v6addrs()

* safe_asprintf to fix /proc/subdir bufferoverflows

There is no max length of /proc/subdir, increasing the value of /proc/sys/kernel/pid_max is one way this can happen

* Fix conversion constant c++ string to variable char array

* Fix strncpy using unrelated MPD_BUFFER_MAX_LENGTH

* Use strncpy instead of strcpy in eve.cc

* Use strncpy instead of strcpy in libmpdclient.cc

* move safe_asprintf back and use ostreams in proc.cc to make sonarcloud happy
This commit is contained in:
Nikolas Garofil 2018-08-07 15:38:36 +02:00 committed by Brenden Matthews
parent a78a750dad
commit 4d5db325d9
10 changed files with 133 additions and 147 deletions

View File

@ -94,6 +94,6 @@ RUN sh -c 'if [ "$X11" = "yes" ] ; then \
libxml2-dev \
tolua++ \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /conky \
&& rm -rf /conky
CMD conky

View File

@ -171,12 +171,9 @@ if(BUILD_IPV6)
endif(BUILD_IPV6)
if(BUILD_HTTP)
find_file(HTTP_H_ microhttpd.h)
#I'm not using check_include_files because microhttpd.h seems to need a lot of different headers and i'm not sure which...
if(NOT HTTP_H_)
message(FATAL_ERROR "Unable to find libmicrohttpd")
endif(NOT HTTP_H_)
set(conky_libs ${conky_libs} -lmicrohttpd)
pkg_check_modules(MICROHTTPD REQUIRED libmicrohttpd>=0.9.25)
set(conky_libs ${conky_libs} ${MICROHTTPD_LIBRARIES})
set(conky_includes ${conky_includes} ${MICROHTTPD_INCLUDE_DIRS})
endif(BUILD_HTTP)
if(BUILD_NCURSES)
@ -435,7 +432,7 @@ endif(BUILD_PULSEAUDIO)
# Common libraries
if(WANT_GLIB)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.36)
set(conky_libs ${conky_libs} ${GLIB_LIBRARIES})
set(conky_includes ${conky_includes} ${GLIB_INCLUDE_DIRS})
endif(WANT_GLIB)

View File

@ -101,7 +101,6 @@ RsvgHandle *rsvg_handle_new_from_file (const char * file_name, GError ** error);
int rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr);
int rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id);
void g_type_init(void);
void g_object_unref(gpointer object);
RsvgHandle * rsvg_create_handle_from_file(const char *);

View File

@ -100,7 +100,6 @@ class audacious_cb : public conky::callback<aud_result> {
public:
audacious_cb(uint32_t period) : Base(period, false, Tuple()) {
#ifdef NEW_AUDACIOUS_FOUND
g_type_init();
DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, nullptr);
if (!connection)
throw std::runtime_error("unable to establish dbus connection");

View File

@ -50,7 +50,6 @@ void update_bmpx() {
GHashTable *metadata;
if (connected == 0) {
g_type_init();
dbus_g_type_specialized_init();
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);

View File

@ -494,8 +494,8 @@ static conky::simple_config_setting<bool> http_refresh("http_refresh", false,
int sendanswer(void *cls, struct MHD_Connection *connection, const char *url,
const char *method, const char *version, const char *upload_data,
size_t *upload_data_size, void **con_cls) {
struct MHD_Response *response = MHD_create_response_from_data(
webpage.length(), (void *)webpage.c_str(), MHD_NO, MHD_NO);
struct MHD_Response *response = MHD_create_response_from_buffer(
webpage.length(), (void *)webpage.c_str(), MHD_RESPMEM_PERSISTENT);
int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response(response);
if (cls || url || method || version || upload_data || upload_data_size ||

View File

@ -96,11 +96,11 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
}
int parseTrainingXml(char *data, Character *s) {
char *skill = "0";
char *level = "0";
char *ends = "";
char *cache = "";
char *isTraining = "0";
char *skill = nullptr;
char *level = nullptr;
char ends[20] = "";
char cache[20] = "";
char *isTraining = nullptr;
xmlNodePtr n;
xmlDocPtr doc = 0;
xmlNodePtr root = 0;
@ -126,7 +126,7 @@ int parseTrainingXml(char *data, Character *s) {
if (!strcasecmp((const char *)c->name, "SkillInTraining")) {
isTraining = (char *)c->children->content;
} else if (!strcasecmp((const char *)c->name, "trainingEndTime")) {
ends = (char *)c->children->content;
strncpy(ends, (const char *)c->children->content, 20);
} else if (!strcasecmp((const char *)c->name, "trainingTypeID")) {
if (c->children->content) skill = (char *)c->children->content;
} else if (!strcasecmp((const char *)c->name, "trainingToLevel")) {
@ -134,14 +134,14 @@ int parseTrainingXml(char *data, Character *s) {
}
}
} else if (!strcasecmp((const char *)n->name, "cachedUntil")) {
cache = (char *)n->children->content;
strncpy(cache, (const char*)n->children->content, 20);
}
}
}
s->isTraining = atoi(isTraining);
s->skill = atoi(skill);
s->level = atoi(level);
if(isTraining == nullptr) s->isTraining = 0; else s->isTraining = atoi(isTraining);
if(skill == nullptr) s->skill = 0; else s->skill = atoi(skill);
if(level == nullptr) s->level = 0; else s->level = atoi(level);
strptime(cache, "%Y-%m-%d %H:%M:%S", &cache_tm);
s->cache = cache_tm;

View File

@ -1371,14 +1371,14 @@ void mpd_sendFindCommand(mpd_Connection *connection, int table,
void mpd_sendListCommand(mpd_Connection *connection, int table,
const char *arg1) {
char st[10];
char st[7];
int len;
char *string;
if (table == MPD_TABLE_ARTIST) {
strncpy(st, "artist", MPD_BUFFER_MAX_LENGTH);
strncpy(st, "artist", strlen("artist") + 1);
} else if (table == MPD_TABLE_ALBUM) {
strncpy(st, "album", MPD_BUFFER_MAX_LENGTH);
strncpy(st, "album", strlen("album") + 1);
} else {
connection->error = 1;
strncpy(connection->errorStr, "unknown table for list",

View File

@ -270,7 +270,7 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size) {
}
// scope
if (ns->v6show_sc) {
char scopestr[3];
char scopestr[4];
sprintf(scopestr, "(%c)", current_v6->scope);
strncat(p, scopestr, p_max_size);
}

View File

@ -35,14 +35,7 @@
#include "conky.h"
#include "core.h"
#include "logging.h"
pid_t strtopid(const char *s) {
long t;
if (sscanf(s, "%ld", &t) != 1) {
return -1;
}
return t;
}
#include <sstream>
char *readfile(const char *filename, int *total_read, char showerror) {
FILE *file;
@ -65,7 +58,7 @@ char *readfile(const char *filename, int *total_read, char showerror) {
return buf;
}
void pid_readlink(char *file, char *p, int p_max_size) {
void pid_readlink(const char *file, char *p, int p_max_size) {
std::unique_ptr<char[]> buf(new char[p_max_size]);
memset(buf.get(), 0, p_max_size);
@ -114,25 +107,25 @@ int inlist(struct ll_string *front, char *string) {
}
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> buf(new char[max_user_text.get(*state)]);
generate_text_internal(buf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/root", strtopid(buf.get()));
pid_readlink(pathbuf, p, p_max_size);
pathstream << PROCDIR "/" << buf.get() << "/root";
pid_readlink(pathstream.str().c_str(), p, p_max_size);
}
void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size) {
char *buf;
int i, bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%d/cmdline", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/cmdline";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
for (i = 0; i < bytes_read - 1; i++) {
if (buf[i] == 0) {
@ -150,24 +143,24 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size) {
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size) {
std::unique_ptr<char[]> buf(new char[p_max_size]);
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/cwd", strtopid(objbuf.get()));
bytes_read = readlink(pathbuf, buf.get(), p_max_size);
pathstream << PROCDIR "/" << objbuf.get() << "/cwd";
bytes_read = readlink(pathstream.str().c_str(), buf.get(), p_max_size);
if (bytes_read != -1) {
buf[bytes_read] = 0;
snprintf(p, p_max_size, "%s", buf.get());
} else {
NORM_ERR(READERR, pathbuf);
NORM_ERR(READERR, pathstream.str().c_str());
}
}
void print_pid_environ(struct text_object *obj, char *p, int p_max_size) {
int i, total_read;
pid_t pid;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
char *buf, *var = strdup(obj->data.s);
;
@ -177,8 +170,8 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size) {
for (i = 0; var[i] != 0; i++) {
var[i] = toupper(var[i]);
}
snprintf(pathbuf, 64, PROCDIR "/%d/environ", pid);
buf = readfile(pathbuf, &total_read, 1);
pathstream << PROCDIR "/" << pid << "/cwd";
buf = readfile(pathstream.str().c_str(), &total_read, 1);
if (buf != nullptr) {
for (i = 0; i < total_read; i += strlen(buf + i) + 1) {
if (strncmp(buf + i, var, strlen(var)) == 0 &&
@ -201,13 +194,13 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size) {
char *buf2;
int bytes_read, total_read;
int i = 0;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/environ", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/environ";
buf = readfile(pathbuf, &total_read, 1);
buf = readfile(pathstream.str().c_str(), &total_read, 1);
if (buf != nullptr) {
for (bytes_read = 0; bytes_read < total_read; buf[i - 1] = ';') {
buf2 = strdup(buf + bytes_read);
@ -223,26 +216,26 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size) {
}
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/exe", strtopid(objbuf.get()));
pid_readlink(pathbuf, p, p_max_size);
pathstream << PROCDIR "/" << objbuf.get() << "/exe";
pid_readlink(pathstream.str().c_str(), p, p_max_size);
}
void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
char *buf = nullptr;
int bytes_read;
long int nice_value;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (!obj->data.s) {
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
sscanf(buf,
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d "
@ -271,8 +264,7 @@ void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
if (dir != nullptr) {
while ((entry = readdir(dir)) != nullptr) {
if (entry->d_name[0] != '.') {
snprintf(buf.get(), p_max_size, "%d/%s", strtopid(objbuf.get()),
entry->d_name);
snprintf(buf.get(), p_max_size, "%s/%s", objbuf.get(), entry->d_name);
length = readlink(buf.get(), buf.get(), p_max_size);
buf[length] = 0;
if (inlist(files_front, buf.get()) == 0) {
@ -299,13 +291,13 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
#define PARENTNOTFOUND "Can't find the process parent in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, PARENT_ENTRY);
if (begin != nullptr) {
@ -316,7 +308,7 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(PARENTNOTFOUND, pathbuf);
NORM_ERR(PARENTNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -326,14 +318,14 @@ void print_pid_priority(struct text_object *obj, char *p, int p_max_size) {
char *buf = nullptr;
int bytes_read;
long int priority;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
sscanf(buf,
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d "
@ -352,13 +344,13 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
#define STATENOTFOUND "Can't find the process state in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, STATE_ENTRY);
if (begin != nullptr) {
@ -371,7 +363,7 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(STATENOTFOUND, pathbuf);
NORM_ERR(STATENOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -380,53 +372,53 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
char *begin, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, STATE_ENTRY);
if (begin != nullptr) {
snprintf(p, p_max_size, "%c", *begin);
} else {
NORM_ERR(STATENOTFOUND, pathbuf);
NORM_ERR(STATENOTFOUND, pathstream.str().c_str());
}
free(buf);
}
}
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/fd/2", strtopid(objbuf.get()));
pid_readlink(pathbuf, p, p_max_size);
pathstream << PROCDIR "/" << objbuf.get() << "/fd/2";
pid_readlink(pathstream.str().c_str(), p, p_max_size);
}
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
char pathbuf[64];
std::ostringstream pathstream;
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/fd/0", strtopid(objbuf.get()));
pid_readlink(pathbuf, p, p_max_size);
pathstream << PROCDIR "/" << objbuf.get() << "/fd/0";
pid_readlink(pathstream.str().c_str(), p, p_max_size);
}
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/fd/1", strtopid(objbuf.get()));
pid_readlink(pathbuf, p, p_max_size);
pathstream << PROCDIR "/" << objbuf.get() << "/fd/1";
pid_readlink(pathstream.str().c_str(), p, p_max_size);
}
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg,
@ -458,14 +450,14 @@ void print_cmdline_to_pid(struct text_object *obj, char *p, int p_max_size) {
struct dirent *entry;
char *buf;
int bytes_read, i;
char pathbuf[64];
std::ostringstream pathstream;
dir = opendir(PROCDIR);
if (dir != nullptr) {
while ((entry = readdir(dir)) != nullptr) {
snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", entry->d_name);
pathstream << PROCDIR "/" << entry->d_name << "/cmdline";
buf = readfile(pathbuf, &bytes_read, 0);
buf = readfile(pathstream.str().c_str(), &bytes_read, 0);
if (buf != nullptr) {
for (i = 0; i < bytes_read - 1; i++) {
if (buf[i] == 0) {
@ -493,13 +485,13 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
"Can't find the number of the threads of the process in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, THREADS_ENTRY);
if (begin != nullptr) {
@ -510,7 +502,7 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(THREADSNOTFOUND, pathbuf);
NORM_ERR(THREADSNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -520,13 +512,13 @@ void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) {
DIR *dir;
struct dirent *entry;
int totallength = 0;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/task", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/task";
dir = opendir(pathbuf);
dir = opendir(pathstream.str().c_str());
if (dir != nullptr) {
while ((entry = readdir(dir)) != nullptr) {
if (entry->d_name[0] != '.') {
@ -549,14 +541,14 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p,
char *buf = nullptr;
int bytes_read;
unsigned long int umtime;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu",
&umtime);
@ -572,14 +564,14 @@ void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) {
char *buf = nullptr;
int bytes_read;
unsigned long int kmtime;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %lu",
&kmtime);
@ -595,14 +587,14 @@ void print_pid_time(struct text_object *obj, char *p, int p_max_size) {
char *buf = nullptr;
int bytes_read;
unsigned long int umtime, kmtime;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
if (*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
buf = readfile(pathbuf, &bytes_read, 1);
pathstream << PROCDIR "/" << objbuf.get() << "/stat";
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu",
&umtime, &kmtime);
@ -620,13 +612,13 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
#define UIDNOTFOUND "Can't find the process real uid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, UID_ENTRY);
if (begin != nullptr) {
@ -637,7 +629,7 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(UIDNOTFOUND, pathbuf);
NORM_ERR(UIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -647,13 +639,13 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
#define EUIDNOTFOUND "Can't find the process effective uid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, UID_ENTRY);
if (begin != nullptr) {
@ -667,7 +659,7 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(EUIDNOTFOUND, pathbuf);
NORM_ERR(EUIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -677,13 +669,13 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
#define SUIDNOTFOUND "Can't find the process saved set uid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, UID_ENTRY);
if (begin != nullptr) {
@ -699,7 +691,7 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(SUIDNOTFOUND, pathbuf);
NORM_ERR(SUIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -709,13 +701,13 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
#define FSUIDNOTFOUND "Can't find the process file system uid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, UID_ENTRY);
if (begin != nullptr) {
@ -733,7 +725,7 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(FSUIDNOTFOUND, pathbuf);
NORM_ERR(FSUIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -744,13 +736,13 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
#define GIDNOTFOUND "Can't find the process real gid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, GID_ENTRY);
if (begin != nullptr) {
@ -761,7 +753,7 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(GIDNOTFOUND, pathbuf);
NORM_ERR(GIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -771,13 +763,13 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
#define EGIDNOTFOUND "Can't find the process effective gid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, GID_ENTRY);
if (begin != nullptr) {
@ -791,7 +783,7 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(EGIDNOTFOUND, pathbuf);
NORM_ERR(EGIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -801,13 +793,13 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
#define SGIDNOTFOUND "Can't find the process saved set gid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, GID_ENTRY);
if (begin != nullptr) {
@ -823,7 +815,7 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(SGIDNOTFOUND, pathbuf);
NORM_ERR(SGIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -833,13 +825,13 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
#define FSGIDNOTFOUND "Can't find the process file system gid in '%s'"
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, GID_ENTRY);
if (begin != nullptr) {
@ -857,7 +849,7 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(FSGIDNOTFOUND, pathbuf);
NORM_ERR(FSGIDNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -867,13 +859,13 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
const char *entry, const char *errorstring) {
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/status", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/status";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, entry);
if (begin != nullptr) {
@ -887,7 +879,7 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size,
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(errorstring, pathbuf);
NORM_ERR(errorstring, pathstream.str().c_str());
}
free(buf);
}
@ -952,13 +944,13 @@ void print_pid_vmpte(struct text_object *obj, char *p, int p_max_size) {
void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/io", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/io";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, READ_ENTRY);
if (begin != nullptr) {
@ -968,7 +960,7 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(READNOTFOUND, pathbuf);
NORM_ERR(READNOTFOUND, pathstream.str().c_str());
}
free(buf);
}
@ -979,13 +971,13 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = nullptr;
int bytes_read;
char pathbuf[64];
std::ostringstream pathstream;
std::unique_ptr<char[]> objbuf(new char[max_user_text.get(*state)]);
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%d/io", strtopid(objbuf.get()));
pathstream << PROCDIR "/" << objbuf.get() << "/io";
buf = readfile(pathbuf, &bytes_read, 1);
buf = readfile(pathstream.str().c_str(), &bytes_read, 1);
if (buf != nullptr) {
begin = strstr(buf, WRITE_ENTRY);
if (begin != nullptr) {
@ -995,7 +987,7 @@ void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
}
snprintf(p, p_max_size, "%s", begin);
} else {
NORM_ERR(WRITENOTFOUND, pathbuf);
NORM_ERR(WRITENOTFOUND, pathstream.str().c_str());
}
free(buf);
}