mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 14:25:03 +02:00
chore: handle all posible malloc failures
This commit is contained in:
parent
6ddbb407da
commit
b2d25198e0
@ -19,6 +19,9 @@ int pam_conversation(int num_msg, const struct pam_message** msg,
|
|||||||
struct pam_response** resp, void* appdata_ptr) {
|
struct pam_response** resp, void* appdata_ptr) {
|
||||||
struct pam_response* reply =
|
struct pam_response* reply =
|
||||||
(struct pam_response*)malloc(sizeof(struct pam_response) * num_msg);
|
(struct pam_response*)malloc(sizeof(struct pam_response) * num_msg);
|
||||||
|
if (!reply) {
|
||||||
|
return PAM_BUF_ERR;
|
||||||
|
}
|
||||||
for (size_t i = 0; i < num_msg; i++) {
|
for (size_t i = 0; i < num_msg; i++) {
|
||||||
reply[i].resp = NULL;
|
reply[i].resp = NULL;
|
||||||
reply[i].resp_retcode = 0;
|
reply[i].resp_retcode = 0;
|
||||||
|
26
src/ui.c
26
src/ui.c
@ -178,14 +178,19 @@ int load(struct Vector* users, struct Vector* sessions) {
|
|||||||
gsessions = sessions;
|
gsessions = sessions;
|
||||||
|
|
||||||
// hostnames larger won't render properly
|
// hostnames larger won't render properly
|
||||||
char* hostname = malloc(VALUES_COL - VALUES_SEPR - BOX_HMARGIN);
|
const u_char HOSTNAME_SIZE = VALUES_COL - VALUES_SEPR - BOX_HMARGIN;
|
||||||
if (gethostname(hostname, VALUES_COL - VALUES_SEPR - BOX_HMARGIN) != 0) {
|
char hostname_buf[HOSTNAME_SIZE];
|
||||||
free(hostname);
|
char* hostname = hostname_buf;
|
||||||
|
if (gethostname(hostname_buf, HOSTNAME_SIZE) != 0) {
|
||||||
hostname = unknown_str;
|
hostname = unknown_str;
|
||||||
} else {
|
} else {
|
||||||
char* hidx =
|
// Ig "successful completion" doesn't contemplate truncation case, so need
|
||||||
(char*)utf8back(&hostname[VALUES_COL - VALUES_SEPR - BOX_HMARGIN - 1]);
|
// to append the unspecified nullbyte
|
||||||
*hidx = '\0';
|
|
||||||
|
// char* hidx =
|
||||||
|
// (char*)utf8back(&hostname[VALUES_COL - VALUES_SEPR - BOX_HMARGIN -
|
||||||
|
// 1]);
|
||||||
|
// *hidx = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
of_session =
|
of_session =
|
||||||
@ -203,7 +208,6 @@ int load(struct Vector* users, struct Vector* sessions) {
|
|||||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
|
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
|
||||||
BOXSTART.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
|
BOXSTART.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
|
||||||
g_config->colors.e_hostname, hostname, g_config->colors.fg);
|
g_config->colors.e_hostname, hostname, g_config->colors.fg);
|
||||||
if (hostname != unknown_str) free(hostname);
|
|
||||||
|
|
||||||
// put date
|
// put date
|
||||||
char* fmtd_time = fmt_time(g_config->behavior.timefmt);
|
char* fmtd_time = fmt_time(g_config->behavior.timefmt);
|
||||||
@ -265,13 +269,9 @@ int load(struct Vector* users, struct Vector* sessions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clean_line(struct uint_point origin, uint line) {
|
void clean_line(struct uint_point origin, uint line) {
|
||||||
static char* line_cleaner = NULL;
|
|
||||||
if (line_cleaner == NULL) {
|
|
||||||
// - outline + nullbyte
|
// - outline + nullbyte
|
||||||
line_cleaner = malloc(BOX_WIDTH - 2 + 1);
|
static char line_cleaner[BOX_WIDTH - 2 + 1] = {
|
||||||
memset(line_cleaner, ' ', BOX_WIDTH - 2);
|
[0 ... BOX_WIDTH - 2 - 1] = ' ', [BOX_WIDTH - 2] = '\0'};
|
||||||
line_cleaner[BOX_WIDTH - 2] = 0;
|
|
||||||
}
|
|
||||||
printf("\x1b[%d;%dH%s", origin.y + line, origin.x + 1, line_cleaner);
|
printf("\x1b[%d;%dH%s", origin.y + line, origin.x + 1, line_cleaner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user