idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
14,500 | static void print_help(void)
{
printf(_("Usage: %s [OPTION]...\n"), program_name);
puts(_("psensor-server is an HTTP server for monitoring hardware "
"sensors remotely."));
puts("");
puts("Options:");
puts(_(" -h, --help display this help and exit\n"
" -v, --version display version information and exit"));
puts("");
puts(_(" -p,--port=PORT webserver port\n"
" -w,--wdir=DIR directory containing webserver pages"));
puts("");
puts(_(" -d, --debug=LEVEL "
"set the debug level, integer between 0 and 3"));
puts(_(" -l, --log-file=PATH set the log file to PATH"));
puts(_(" --sensor-log-file=PATH set the sensor log file to PATH"));
puts(_(" --sensor-log-interval=S "
"set the sensor log interval to S (seconds)"));
puts("");
printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
puts("");
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
| Dir. Trav. | 0 | static void print_help(void)
{
printf(_("Usage: %s [OPTION]...\n"), program_name);
puts(_("psensor-server is an HTTP server for monitoring hardware "
"sensors remotely."));
puts("");
puts("Options:");
puts(_(" -h, --help display this help and exit\n"
" -v, --version display version information and exit"));
puts("");
puts(_(" -p,--port=PORT webserver port\n"
" -w,--wdir=DIR directory containing webserver pages"));
puts("");
puts(_(" -d, --debug=LEVEL "
"set the debug level, integer between 0 and 3"));
puts(_(" -l, --log-file=PATH set the log file to PATH"));
puts(_(" --sensor-log-file=PATH set the sensor log file to PATH"));
puts(_(" --sensor-log-interval=S "
"set the sensor log interval to S (seconds)"));
puts("");
printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
puts("");
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
| @@ -23,6 +23,7 @@
#include <libintl.h>
#define _(str) gettext(str)
+#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -245,15 +246,25 @@ static struct MHD_Response *create_response_file(const char *nurl,
static struct MHD_Response *
create_response(const char *nurl, const char *method, unsigned int *rp_code)
{
- char *page, *fpath;
+ char *page, *fpath, *rpath;
struct MHD_Response *resp = NULL;
+ int n;
if (!strncmp(nurl, URL_BASE_API_1_1, strlen(URL_BASE_API_1_1))) {
resp = create_response_api(nurl, method, rp_code);
} else {
fpath = get_path(nurl, server_data.www_dir);
- resp = create_response_file(nurl, method, rp_code, fpath);
+ rpath = realpath(fpath, NULL);
+ if (rpath) {
+ n = strlen(server_data.www_dir);
+ if (!strncmp(server_data.www_dir, rpath, n))
+ resp = create_response_file(nurl,
+ method,
+ rp_code,
+ fpath);
+ free(rpath);
+ }
free(fpath);
}
@@ -349,7 +360,7 @@ int main(int argc, char *argv[])
switch (optc) {
case 'w':
if (optarg)
- server_data.www_dir = strdup(optarg);
+ server_data.www_dir = realpath(optarg, NULL);
break;
case 'p':
if (optarg)
@@ -388,8 +399,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (!server_data.www_dir)
- server_data.www_dir = strdup(DEFAULT_WWW_DIR);
+ if (!server_data.www_dir) {
+ server_data.www_dir = realpath(DEFAULT_WWW_DIR, NULL);
+ if (!server_data.www_dir) {
+ fprintf(stderr,
+ _("Webserver directory does not exist.\n"));
+ exit(EXIT_FAILURE);
+ }
+ }
if (!log_file)
log_file = strdup(DEFAULT_LOG_FILE); | CWE-22 | null | null |
14,501 | static void print_version(void)
{
printf("psensor-server %s\n", VERSION);
printf(_("Copyright (C) %s jeanfi@gmail.com\n"
"License GPLv2: GNU GPL version 2 or later "
"<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"),
"2010-2012");
}
| Dir. Trav. | 0 | static void print_version(void)
{
printf("psensor-server %s\n", VERSION);
printf(_("Copyright (C) %s jeanfi@gmail.com\n"
"License GPLv2: GNU GPL version 2 or later "
"<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"),
"2010-2012");
}
| @@ -23,6 +23,7 @@
#include <libintl.h>
#define _(str) gettext(str)
+#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -245,15 +246,25 @@ static struct MHD_Response *create_response_file(const char *nurl,
static struct MHD_Response *
create_response(const char *nurl, const char *method, unsigned int *rp_code)
{
- char *page, *fpath;
+ char *page, *fpath, *rpath;
struct MHD_Response *resp = NULL;
+ int n;
if (!strncmp(nurl, URL_BASE_API_1_1, strlen(URL_BASE_API_1_1))) {
resp = create_response_api(nurl, method, rp_code);
} else {
fpath = get_path(nurl, server_data.www_dir);
- resp = create_response_file(nurl, method, rp_code, fpath);
+ rpath = realpath(fpath, NULL);
+ if (rpath) {
+ n = strlen(server_data.www_dir);
+ if (!strncmp(server_data.www_dir, rpath, n))
+ resp = create_response_file(nurl,
+ method,
+ rp_code,
+ fpath);
+ free(rpath);
+ }
free(fpath);
}
@@ -349,7 +360,7 @@ int main(int argc, char *argv[])
switch (optc) {
case 'w':
if (optarg)
- server_data.www_dir = strdup(optarg);
+ server_data.www_dir = realpath(optarg, NULL);
break;
case 'p':
if (optarg)
@@ -388,8 +399,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (!server_data.www_dir)
- server_data.www_dir = strdup(DEFAULT_WWW_DIR);
+ if (!server_data.www_dir) {
+ server_data.www_dir = realpath(DEFAULT_WWW_DIR, NULL);
+ if (!server_data.www_dir) {
+ fprintf(stderr,
+ _("Webserver directory does not exist.\n"));
+ exit(EXIT_FAILURE);
+ }
+ }
if (!log_file)
log_file = strdup(DEFAULT_LOG_FILE); | CWE-22 | null | null |
14,502 | _env_path_append(const char *env, const char *path)
{
char *p, *s;
const char *p2;
int len = 0, len2 = 0;
if (!path) return;
p = getenv(env);
p2 = path;
len2 = strlen(p2);
if (p)
{
len = strlen(p);
if ((!strcmp(p, p2)) ||
((len > len2) &&
(!strcmp((p + len - len2), p2)) &&
(p[len - len2 - 1] == ':')))
return;
}
s = malloc(len + 1 + len2 + 1);
if (s)
{
s[0] = 0;
if (p)
{
strcat(s, p);
strcat(s, ":");
}
strcat(s, p2);
env_set(env, s);
free(s);
}
}
| +Priv | 0 | _env_path_append(const char *env, const char *path)
{
char *p, *s;
const char *p2;
int len = 0, len2 = 0;
if (!path) return;
p = getenv(env);
p2 = path;
len2 = strlen(p2);
if (p)
{
len = strlen(p);
if ((!strcmp(p, p2)) ||
((len > len2) &&
(!strcmp((p + len - len2), p2)) &&
(p[len - len2 - 1] == ':')))
return;
}
s = malloc(len + 1 + len2 + 1);
if (s)
{
s[0] = 0;
if (p)
{
strcat(s, p);
strcat(s, ":");
}
strcat(s, p2);
env_set(env, s);
free(s);
}
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,503 | _env_path_prepend(const char *env, const char *path)
{
char *p, *s;
const char *p2;
int len = 0, len2 = 0;
if (!path) return;
p = getenv(env);
p2 = path;
len2 = strlen(p2);
if (p)
{
len = strlen(p);
if ((!strcmp(p, p2)) ||
((len > len2) &&
(!strncmp(p, p2, len2)) &&
(p[len2] == ':')))
return;
}
s = malloc(len + 1 + len2 + 1);
if (s)
{
s[0] = 0;
strcat(s, p2);
if (p)
{
strcat(s, ":");
strcat(s, p);
}
env_set(env, s);
free(s);
}
}
| +Priv | 0 | _env_path_prepend(const char *env, const char *path)
{
char *p, *s;
const char *p2;
int len = 0, len2 = 0;
if (!path) return;
p = getenv(env);
p2 = path;
len2 = strlen(p2);
if (p)
{
len = strlen(p);
if ((!strcmp(p, p2)) ||
((len > len2) &&
(!strncmp(p, p2, len2)) &&
(p[len2] == ':')))
return;
}
s = malloc(len + 1 + len2 + 1);
if (s)
{
s[0] = 0;
strcat(s, p2);
if (p)
{
strcat(s, ":");
strcat(s, p);
}
env_set(env, s);
free(s);
}
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,504 | _sigusr1(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
{
struct sigaction action;
/* release ptrace */
stop_ptrace = EINA_TRUE;
action.sa_sigaction = _sigusr1;
action.sa_flags = SA_RESETHAND;
sigemptyset(&action.sa_mask);
sigaction(SIGUSR1, &action, NULL);
}
| +Priv | 0 | _sigusr1(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
{
struct sigaction action;
/* release ptrace */
stop_ptrace = EINA_TRUE;
action.sa_sigaction = _sigusr1;
action.sa_flags = SA_RESETHAND;
sigemptyset(&action.sa_mask);
sigaction(SIGUSR1, &action, NULL);
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,505 | find_valgrind(char *path, size_t path_len)
{
const char *env = getenv("PATH");
while (env)
{
const char *p = strchr(env, ':');
ssize_t p_len;
if (p) p_len = p - env;
else p_len = strlen(env);
if (p_len <= 0) goto next;
else if (p_len + sizeof("/valgrind") >= path_len)
goto next;
memcpy(path, env, p_len);
memcpy(path + p_len, "/valgrind", sizeof("/valgrind"));
if (access(path, X_OK | R_OK) == 0) return 1;
next:
if (p) env = p + 1;
else break;
}
path[0] = '\0';
return 0;
}
| +Priv | 0 | find_valgrind(char *path, size_t path_len)
{
const char *env = getenv("PATH");
while (env)
{
const char *p = strchr(env, ':');
ssize_t p_len;
if (p) p_len = p - env;
else p_len = strlen(env);
if (p_len <= 0) goto next;
else if (p_len + sizeof("/valgrind") >= path_len)
goto next;
memcpy(path, env, p_len);
memcpy(path + p_len, "/valgrind", sizeof("/valgrind"));
if (access(path, X_OK | R_OK) == 0) return 1;
next:
if (p) env = p + 1;
else break;
}
path[0] = '\0';
return 0;
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,506 | prefix_determine(char *argv0)
{
pfx = eina_prefix_new(argv0, prefix_determine,
"E", "enlightenment", "AUTHORS",
PACKAGE_BIN_DIR, PACKAGE_LIB_DIR,
PACKAGE_DATA_DIR, LOCALE_DIR);
if (!pfx) return 0;
return 1;
}
| +Priv | 0 | prefix_determine(char *argv0)
{
pfx = eina_prefix_new(argv0, prefix_determine,
"E", "enlightenment", "AUTHORS",
PACKAGE_BIN_DIR, PACKAGE_LIB_DIR,
PACKAGE_DATA_DIR, LOCALE_DIR);
if (!pfx) return 0;
return 1;
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,507 | valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgrind_tool, char *valgrind_path, const char *valgrind_log)
{
int i = 0;
if (valgrind_tool)
{
dst[i++] = valgrind_path;
switch (valgrind_tool)
{
case 1: dst[i++] = "--tool=massif"; break;
case 2: dst[i++] = "--tool=callgrind"; break;
}
return i;
}
if (valgrind_gdbserver) dst[i++] = "--db-attach=yes";
if (!valgrind_mode) return 0;
dst[i++] = valgrind_path;
dst[i++] = "--num-callers=40";
dst[i++] = "--track-origins=yes";
dst[i++] = "--malloc-fill=13"; /* invalid pointer, make it crash */
if (valgrind_log)
{
static char logparam[PATH_MAX + sizeof("--log-file=")];
snprintf(logparam, sizeof(logparam), "--log-file=%s", valgrind_log);
dst[i++] = logparam;
}
if (valgrind_mode & 2) dst[i++] = "--trace-children=yes";
if (valgrind_mode & 4)
{
dst[i++] = "--leak-check=full";
dst[i++] = "--leak-resolution=high";
dst[i++] = "--track-fds=yes";
}
if (valgrind_mode & 8) dst[i++] = "--show-reachable=yes";
return i;
}
| +Priv | 0 | valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgrind_tool, char *valgrind_path, const char *valgrind_log)
{
int i = 0;
if (valgrind_tool)
{
dst[i++] = valgrind_path;
switch (valgrind_tool)
{
case 1: dst[i++] = "--tool=massif"; break;
case 2: dst[i++] = "--tool=callgrind"; break;
}
return i;
}
if (valgrind_gdbserver) dst[i++] = "--db-attach=yes";
if (!valgrind_mode) return 0;
dst[i++] = valgrind_path;
dst[i++] = "--num-callers=40";
dst[i++] = "--track-origins=yes";
dst[i++] = "--malloc-fill=13"; /* invalid pointer, make it crash */
if (valgrind_log)
{
static char logparam[PATH_MAX + sizeof("--log-file=")];
snprintf(logparam, sizeof(logparam), "--log-file=%s", valgrind_log);
dst[i++] = logparam;
}
if (valgrind_mode & 2) dst[i++] = "--trace-children=yes";
if (valgrind_mode & 4)
{
dst[i++] = "--leak-check=full";
dst[i++] = "--leak-resolution=high";
dst[i++] = "--track-fds=yes";
}
if (valgrind_mode & 8) dst[i++] = "--show-reachable=yes";
return i;
}
| @@ -567,8 +567,7 @@ main(int argc, char **argv)
{
/* call e_sys gdb */
snprintf(buffer, 4096,
- "%s/enlightenment/utils/enlightenment_sys gdb %i %s/.e-crashdump.txt",
- eina_prefix_lib_get(pfx),
+ "gdb %i %s/.e-crashdump.txt",
child,
home);
r = system(buffer); | CWE-264 | null | null |
14,508 | auth_action_ok(char *a,
gid_t gid,
gid_t *gl,
int gn,
gid_t egid)
{
struct passwd *pw;
struct group *gp;
char *usr = NULL, **grp, *g;
int ret, i, j;
pw = getpwuid(uid);
if (!pw) return 0;
usr = pw->pw_name;
if (!usr) return 0;
grp = alloca(sizeof(char *) * (gn + 1 + 1));
j = 0;
gp = getgrgid(gid);
if (gp)
{
grp[j] = gp->gr_name;
j++;
}
for (i = 0; i < gn; i++)
{
if (gl[i] != egid)
{
gp = getgrgid(gl[i]);
if (gp)
{
g = alloca(strlen(gp->gr_name) + 1);
strcpy(g, gp->gr_name);
grp[j] = g;
j++;
}
}
}
grp[j] = NULL;
/* first stage - check:
* PREFIX/etc/enlightenment/sysactions.conf
*/
ret = auth_etc_enlightenment_sysactions(a, usr, grp);
if (ret == 1) return 1;
else if (ret == -1)
return 0;
/* the DEFAULT - allow */
return 1;
}
| +Priv | 0 | auth_action_ok(char *a,
gid_t gid,
gid_t *gl,
int gn,
gid_t egid)
{
struct passwd *pw;
struct group *gp;
char *usr = NULL, **grp, *g;
int ret, i, j;
pw = getpwuid(uid);
if (!pw) return 0;
usr = pw->pw_name;
if (!usr) return 0;
grp = alloca(sizeof(char *) * (gn + 1 + 1));
j = 0;
gp = getgrgid(gid);
if (gp)
{
grp[j] = gp->gr_name;
j++;
}
for (i = 0; i < gn; i++)
{
if (gl[i] != egid)
{
gp = getgrgid(gl[i]);
if (gp)
{
g = alloca(strlen(gp->gr_name) + 1);
strcpy(g, gp->gr_name);
grp[j] = g;
j++;
}
}
}
grp[j] = NULL;
/* first stage - check:
* PREFIX/etc/enlightenment/sysactions.conf
*/
ret = auth_etc_enlightenment_sysactions(a, usr, grp);
if (ret == 1) return 1;
else if (ret == -1)
return 0;
/* the DEFAULT - allow */
return 1;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,509 | auth_etc_enlightenment_sysactions(char *a,
char *u,
char **g)
{
FILE *f;
char file[4096], buf[4096], id[4096], ugname[4096], perm[4096], act[4096];
char *p, *pp, *s, **gp;
int ok = 0;
size_t len, line = 0;
int allow = 0;
int deny = 0;
snprintf(file, sizeof(file), "/etc/enlightenment/sysactions.conf");
f = fopen(file, "r");
if (!f)
{
snprintf(file, sizeof(file), PACKAGE_SYSCONF_DIR "/enlightenment/sysactions.conf");
f = fopen(file, "r");
if (!f) return 0;
}
auth_etc_enlightenment_sysactions_perm(file);
while (fgets(buf, sizeof(buf), f))
{
line++;
len = strlen(buf);
if (len < 1) continue;
if (buf[len - 1] == '\n') buf[len - 1] = 0;
/* format:
*
* # comment
* user: username [allow:|deny:] halt reboot ...
* group: groupname [allow:|deny:] suspend ...
*/
if (buf[0] == '#') continue;
p = buf;
p = get_word(p, id);
p = get_word(p, ugname);
pp = p;
p = get_word(p, perm);
allow = 0;
deny = 0;
if (!strcmp(id, "user:"))
{
if (!fnmatch(ugname, u, 0))
{
if (!strcmp(perm, "allow:")) allow = 1;
else if (!strcmp(perm, "deny:"))
deny = 1;
else
goto malformed;
}
else
continue;
}
else if (!strcmp(id, "group:"))
{
Eina_Bool matched = EINA_FALSE;
for (gp = g; *gp; gp++)
{
if (!fnmatch(ugname, *gp, 0))
{
matched = EINA_TRUE;
if (!strcmp(perm, "allow:")) allow = 1;
else if (!strcmp(perm, "deny:"))
deny = 1;
else
goto malformed;
}
}
if (!matched) continue;
}
else if (!strcmp(id, "action:"))
{
while ((*pp) && (isspace(*pp)))
pp++;
s = eina_hash_find(actions, ugname);
if (s) eina_hash_del(actions, ugname, s);
if (!actions) actions = eina_hash_string_superfast_new(free);
eina_hash_add(actions, ugname, strdup(pp));
continue;
}
else if (id[0] == 0)
continue;
else
goto malformed;
for (;; )
{
p = get_word(p, act);
if (act[0] == 0) break;
if (!fnmatch(act, a, 0))
{
if (allow) ok = 1;
else if (deny)
ok = -1;
goto done;
}
}
continue;
malformed:
printf("WARNING: %s:%zu\n"
"LINE: '%s'\n"
"MALFORMED LINE. SKIPPED.\n",
file, line, buf);
}
done:
fclose(f);
return ok;
}
| +Priv | 0 | auth_etc_enlightenment_sysactions(char *a,
char *u,
char **g)
{
FILE *f;
char file[4096], buf[4096], id[4096], ugname[4096], perm[4096], act[4096];
char *p, *pp, *s, **gp;
int ok = 0;
size_t len, line = 0;
int allow = 0;
int deny = 0;
snprintf(file, sizeof(file), "/etc/enlightenment/sysactions.conf");
f = fopen(file, "r");
if (!f)
{
snprintf(file, sizeof(file), PACKAGE_SYSCONF_DIR "/enlightenment/sysactions.conf");
f = fopen(file, "r");
if (!f) return 0;
}
auth_etc_enlightenment_sysactions_perm(file);
while (fgets(buf, sizeof(buf), f))
{
line++;
len = strlen(buf);
if (len < 1) continue;
if (buf[len - 1] == '\n') buf[len - 1] = 0;
/* format:
*
* # comment
* user: username [allow:|deny:] halt reboot ...
* group: groupname [allow:|deny:] suspend ...
*/
if (buf[0] == '#') continue;
p = buf;
p = get_word(p, id);
p = get_word(p, ugname);
pp = p;
p = get_word(p, perm);
allow = 0;
deny = 0;
if (!strcmp(id, "user:"))
{
if (!fnmatch(ugname, u, 0))
{
if (!strcmp(perm, "allow:")) allow = 1;
else if (!strcmp(perm, "deny:"))
deny = 1;
else
goto malformed;
}
else
continue;
}
else if (!strcmp(id, "group:"))
{
Eina_Bool matched = EINA_FALSE;
for (gp = g; *gp; gp++)
{
if (!fnmatch(ugname, *gp, 0))
{
matched = EINA_TRUE;
if (!strcmp(perm, "allow:")) allow = 1;
else if (!strcmp(perm, "deny:"))
deny = 1;
else
goto malformed;
}
}
if (!matched) continue;
}
else if (!strcmp(id, "action:"))
{
while ((*pp) && (isspace(*pp)))
pp++;
s = eina_hash_find(actions, ugname);
if (s) eina_hash_del(actions, ugname, s);
if (!actions) actions = eina_hash_string_superfast_new(free);
eina_hash_add(actions, ugname, strdup(pp));
continue;
}
else if (id[0] == 0)
continue;
else
goto malformed;
for (;; )
{
p = get_word(p, act);
if (act[0] == 0) break;
if (!fnmatch(act, a, 0))
{
if (allow) ok = 1;
else if (deny)
ok = -1;
goto done;
}
}
continue;
malformed:
printf("WARNING: %s:%zu\n"
"LINE: '%s'\n"
"MALFORMED LINE. SKIPPED.\n",
file, line, buf);
}
done:
fclose(f);
return ok;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,510 | auth_etc_enlightenment_sysactions_perm(char *path)
{
struct stat st;
if (stat(path, &st) == -1)
return;
if ((st.st_mode & S_IWGRP) || (st.st_mode & S_IXGRP) ||
(st.st_mode & S_IWOTH) || (st.st_mode & S_IXOTH))
{
printf("ERROR: CONFIGURATION FILE HAS BAD PERMISSIONS (writable by group and/or others)\n");
exit(10);
}
}
| +Priv | 0 | auth_etc_enlightenment_sysactions_perm(char *path)
{
struct stat st;
if (stat(path, &st) == -1)
return;
if ((st.st_mode & S_IWGRP) || (st.st_mode & S_IXGRP) ||
(st.st_mode & S_IWOTH) || (st.st_mode & S_IXOTH))
{
printf("ERROR: CONFIGURATION FILE HAS BAD PERMISSIONS (writable by group and/or others)\n");
exit(10);
}
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,511 | check_uuid(const char *uuid)
{
const char *p;
for (p = uuid; p[0]; p++)
if ((!isalnum(*p)) && (*p != '-')) return EINA_FALSE;
return EINA_TRUE;
}
| +Priv | 0 | check_uuid(const char *uuid)
{
const char *p;
for (p = uuid; p[0]; p++)
if ((!isalnum(*p)) && (*p != '-')) return EINA_FALSE;
return EINA_TRUE;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,512 | get_word(char *s,
char *d)
{
char *p1, *p2;
p1 = s;
p2 = d;
while (*p1)
{
if (p2 == d)
{
if (isspace(*p1))
{
p1++;
continue;
}
}
if (isspace(*p1)) break;
*p2 = *p1;
p1++;
p2++;
}
*p2 = 0;
return p1;
}
| +Priv | 0 | get_word(char *s,
char *d)
{
char *p1, *p2;
p1 = s;
p2 = d;
while (*p1)
{
if (p2 == d)
{
if (isspace(*p1))
{
p1++;
continue;
}
}
if (isspace(*p1)) break;
*p2 = *p1;
p1++;
p2++;
}
*p2 = 0;
return p1;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,513 | mount_args_check(int argc, char **argv, const char *action)
{
Eina_Bool opts = EINA_FALSE;
struct stat st;
const char *node;
char buf[PATH_MAX];
if (!strcmp(action, "mount"))
{
/* will ALWAYS be:
/path/to/mount -o nosuid,uid=XYZ,[utf8,] UUID=XXXX-XXXX[-XXXX-XXXX] /media/$devnode
*/
if (argc != 6) return EINA_FALSE;
if (argv[2][0] == '-')
{
/* disallow any -options other than -o */
if (strcmp(argv[2], "-o")) return EINA_FALSE;
opts = mountopts_check(argv[3]);
}
if (!opts) return EINA_FALSE;
if (!strncmp(argv[4], "UUID=", sizeof("UUID=") - 1))
{
if (!check_uuid(argv[4] + 5)) return EINA_FALSE;
}
else
{
if (strncmp(argv[4], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[4], &st)) return EINA_FALSE;
}
node = strrchr(argv[5], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[5] != 6) return EINA_FALSE;
snprintf(buf, sizeof(buf), "/dev%s", node);
if (stat(buf, &st)) return EINA_FALSE;
}
else if (!strcmp(action, "umount"))
{
/* will ALWAYS be:
/path/to/umount /dev/$devnode
*/
if (argc != 3) return EINA_FALSE;
if (strncmp(argv[2], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[2], &st)) return EINA_FALSE;
node = strrchr(argv[2], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[2] != 4) return EINA_FALSE;
/* this is good, but it prevents umounting user-mounted removable media;
* need to figure out a better way...
*
snprintf(buf, sizeof(buf), "/media%s", node);
if (stat(buf, &st)) return EINA_FALSE;
if (!S_ISDIR(st.st_mode)) return EINA_FALSE;
*/
}
else if (!strcmp(action, "eject"))
{
/* will ALWAYS be:
/path/to/eject /dev/$devnode
*/
if (argc != 3) return EINA_FALSE;
if (strncmp(argv[2], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[2], &st)) return EINA_FALSE;
node = strrchr(argv[2], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[2] != 4) return EINA_FALSE;
}
else return EINA_FALSE;
return EINA_TRUE;
}
| +Priv | 0 | mount_args_check(int argc, char **argv, const char *action)
{
Eina_Bool opts = EINA_FALSE;
struct stat st;
const char *node;
char buf[PATH_MAX];
if (!strcmp(action, "mount"))
{
/* will ALWAYS be:
/path/to/mount -o nosuid,uid=XYZ,[utf8,] UUID=XXXX-XXXX[-XXXX-XXXX] /media/$devnode
*/
if (argc != 6) return EINA_FALSE;
if (argv[2][0] == '-')
{
/* disallow any -options other than -o */
if (strcmp(argv[2], "-o")) return EINA_FALSE;
opts = mountopts_check(argv[3]);
}
if (!opts) return EINA_FALSE;
if (!strncmp(argv[4], "UUID=", sizeof("UUID=") - 1))
{
if (!check_uuid(argv[4] + 5)) return EINA_FALSE;
}
else
{
if (strncmp(argv[4], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[4], &st)) return EINA_FALSE;
}
node = strrchr(argv[5], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[5] != 6) return EINA_FALSE;
snprintf(buf, sizeof(buf), "/dev%s", node);
if (stat(buf, &st)) return EINA_FALSE;
}
else if (!strcmp(action, "umount"))
{
/* will ALWAYS be:
/path/to/umount /dev/$devnode
*/
if (argc != 3) return EINA_FALSE;
if (strncmp(argv[2], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[2], &st)) return EINA_FALSE;
node = strrchr(argv[2], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[2] != 4) return EINA_FALSE;
/* this is good, but it prevents umounting user-mounted removable media;
* need to figure out a better way...
*
snprintf(buf, sizeof(buf), "/media%s", node);
if (stat(buf, &st)) return EINA_FALSE;
if (!S_ISDIR(st.st_mode)) return EINA_FALSE;
*/
}
else if (!strcmp(action, "eject"))
{
/* will ALWAYS be:
/path/to/eject /dev/$devnode
*/
if (argc != 3) return EINA_FALSE;
if (strncmp(argv[2], "/dev/", 5)) return EINA_FALSE;
if (stat(argv[2], &st)) return EINA_FALSE;
node = strrchr(argv[2], '/');
if (!node) return EINA_FALSE;
if (!node[1]) return EINA_FALSE;
if (node - argv[2] != 4) return EINA_FALSE;
}
else return EINA_FALSE;
return EINA_TRUE;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,514 | mountopts_check(const char *opts)
{
char buf[64];
const char *p;
char *end;
unsigned long muid;
Eina_Bool nosuid, nodev, noexec, nuid;
nosuid = nodev = noexec = nuid = EINA_FALSE;
/* these are the only possible options which can be present here; check them strictly */
if (eina_strlcpy(buf, opts, sizeof(buf)) >= sizeof(buf)) return EINA_FALSE;
for (p = buf; p && p[1]; p = strchr(p + 1, ','))
{
if (p[0] == ',') p++;
#define CMP(OPT) \
if (!strncmp(p, OPT, sizeof(OPT) - 1))
CMP("nosuid,")
{
nosuid = EINA_TRUE;
continue;
}
CMP("nodev,")
{
nodev = EINA_TRUE;
continue;
}
CMP("noexec,")
{
noexec = EINA_TRUE;
continue;
}
CMP("utf8,") continue;
CMP("utf8=0,") continue;
CMP("utf8=1,") continue;
CMP("iocharset=utf8,") continue;
CMP("uid=")
{
p += 4;
errno = 0;
muid = strtoul(p, &end, 10);
if (muid == ULONG_MAX) return EINA_FALSE;
if (errno) return EINA_FALSE;
if (end[0] != ',') return EINA_FALSE;
if (muid != uid) return EINA_FALSE;
nuid = EINA_TRUE;
continue;
}
return EINA_FALSE;
}
if ((!nosuid) || (!nodev) || (!noexec) || (!nuid)) return EINA_FALSE;
return EINA_TRUE;
}
| +Priv | 0 | mountopts_check(const char *opts)
{
char buf[64];
const char *p;
char *end;
unsigned long muid;
Eina_Bool nosuid, nodev, noexec, nuid;
nosuid = nodev = noexec = nuid = EINA_FALSE;
/* these are the only possible options which can be present here; check them strictly */
if (eina_strlcpy(buf, opts, sizeof(buf)) >= sizeof(buf)) return EINA_FALSE;
for (p = buf; p && p[1]; p = strchr(p + 1, ','))
{
if (p[0] == ',') p++;
#define CMP(OPT) \
if (!strncmp(p, OPT, sizeof(OPT) - 1))
CMP("nosuid,")
{
nosuid = EINA_TRUE;
continue;
}
CMP("nodev,")
{
nodev = EINA_TRUE;
continue;
}
CMP("noexec,")
{
noexec = EINA_TRUE;
continue;
}
CMP("utf8,") continue;
CMP("utf8=0,") continue;
CMP("utf8=1,") continue;
CMP("iocharset=utf8,") continue;
CMP("uid=")
{
p += 4;
errno = 0;
muid = strtoul(p, &end, 10);
if (muid == ULONG_MAX) return EINA_FALSE;
if (errno) return EINA_FALSE;
if (end[0] != ',') return EINA_FALSE;
if (muid != uid) return EINA_FALSE;
nuid = EINA_TRUE;
continue;
}
return EINA_FALSE;
}
if ((!nosuid) || (!nodev) || (!noexec) || (!nuid)) return EINA_FALSE;
return EINA_TRUE;
}
| @@ -1,5 +1,11 @@
#include "config.h"
+#define __USE_MISC
+#define _SVID_SOURCE
+#ifdef HAVE_FEATURES_H
+# include <features.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -53,7 +59,6 @@ main(int argc,
const char *act;
#endif
gid_t gid, gl[65536], egid;
- int pid = 0;
for (i = 1; i < argc; i++)
{
@@ -75,21 +80,6 @@ main(int argc,
test = 1;
action = argv[2];
}
- else if (!strcmp(argv[1], "gdb"))
- {
- if (argc != 4) exit(1);
- char *end = NULL;
-
- action = argv[1];
- pid = strtoul(argv[2], &end, 10);
- if (end == NULL || *end != '\0')
- {
- printf("Invalid pid for '%s'.\n", argv[3]);
- exit(0);
- }
-
- output = argv[3];
- }
else if (!strcmp(argv[1], "l2ping"))
{
action = argv[1];
@@ -161,27 +151,7 @@ main(int argc,
exit(20);
}
- if (!strcmp(action, "gdb"))
- {
- char buffer[4096];
- int r;
-
- snprintf(buffer, 4096,
- "%s --pid=%i "
- "-batch "
- "-ex 'set logging file %s' "
- "-ex 'set logging on' "
- "-ex 'thread apply all backtrace full' "
- "-ex detach > /dev/null 2>&1 < /dev/zero",
- cmd,
- pid,
- output ?: "e-output.txt");
-
- r = system(buffer);
-
- exit(WEXITSTATUS(r));
- }
- else if (!test && !strcmp(action, "l2ping"))
+ if (!test && !strcmp(action, "l2ping"))
{
char tmp[128];
double latency;
@@ -193,6 +163,23 @@ main(int argc,
return (latency < 0) ? 1 : 0;
}
+ /* sanitize environment */
+#ifdef HAVE_UNSETENV
+# define NOENV(x) unsetenv(x)
+#else
+# define NOENV(x)
+#endif
+ NOENV("IFS");
+ NOENV("LD_PRELOAD");
+ NOENV("PYTHONPATH");
+ NOENV("LD_LIBRARY_PATH");
+#ifdef HAVE_CLEARENV
+ clearenv();
+#endif
+ /* set path and ifs to minimal defaults */
+ putenv("PATH=/bin:/usr/bin");
+ putenv("IFS= \t\n");
+
if ((!test)
#ifdef HAVE_EEZE_MOUNT
&& (!mnt) | CWE-264 | null | null |
14,515 | pango_glyph_string_copy (PangoGlyphString *string)
{
PangoGlyphString *new_string;
if (string == NULL)
return NULL;
new_string = g_slice_new (PangoGlyphString);
*new_string = *string;
new_string->glyphs = g_memdup (string->glyphs,
string->space * sizeof (PangoGlyphInfo));
new_string->log_clusters = g_memdup (string->log_clusters,
string->space * sizeof (gint));
return new_string;
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_copy (PangoGlyphString *string)
{
PangoGlyphString *new_string;
if (string == NULL)
return NULL;
new_string = g_slice_new (PangoGlyphString);
*new_string = *string;
new_string->glyphs = g_memdup (string->glyphs,
string->space * sizeof (PangoGlyphInfo));
new_string->log_clusters = g_memdup (string->log_clusters,
string->space * sizeof (gint));
return new_string;
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,516 | pango_glyph_string_extents (PangoGlyphString *glyphs,
PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
pango_glyph_string_extents_range (glyphs, 0, glyphs->num_glyphs,
font, ink_rect, logical_rect);
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_extents (PangoGlyphString *glyphs,
PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
pango_glyph_string_extents_range (glyphs, 0, glyphs->num_glyphs,
font, ink_rect, logical_rect);
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,517 | pango_glyph_string_extents_range (PangoGlyphString *glyphs,
int start,
int end,
PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
int x_pos = 0;
int i;
/* Note that the handling of empty rectangles for ink
* and logical rectangles is different. A zero-height ink
* rectangle makes no contribution to the overall ink rect,
* while a zero-height logical rect still reserves horizontal
* width. Also, we may return zero-width, positive height
* logical rectangles, while we'll never do that for the
* ink rect.
*/
g_return_if_fail (start <= end);
if (G_UNLIKELY (!ink_rect && !logical_rect))
return;
if (ink_rect)
{
ink_rect->x = 0;
ink_rect->y = 0;
ink_rect->width = 0;
ink_rect->height = 0;
}
if (logical_rect)
{
logical_rect->x = 0;
logical_rect->y = 0;
logical_rect->width = 0;
logical_rect->height = 0;
}
for (i = start; i < end; i++)
{
PangoRectangle glyph_ink;
PangoRectangle glyph_logical;
PangoGlyphGeometry *geometry = &glyphs->glyphs[i].geometry;
pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph,
ink_rect ? &glyph_ink : NULL,
logical_rect ? &glyph_logical : NULL);
if (ink_rect && glyph_ink.width != 0 && glyph_ink.height != 0)
{
if (ink_rect->width == 0 || ink_rect->height == 0)
{
ink_rect->x = x_pos + glyph_ink.x + geometry->x_offset;
ink_rect->width = glyph_ink.width;
ink_rect->y = glyph_ink.y + geometry->y_offset;
ink_rect->height = glyph_ink.height;
}
else
{
int new_x, new_y;
new_x = MIN (ink_rect->x, x_pos + glyph_ink.x + geometry->x_offset);
ink_rect->width = MAX (ink_rect->x + ink_rect->width,
x_pos + glyph_ink.x + glyph_ink.width + geometry->x_offset) - new_x;
ink_rect->x = new_x;
new_y = MIN (ink_rect->y, glyph_ink.y + geometry->y_offset);
ink_rect->height = MAX (ink_rect->y + ink_rect->height,
glyph_ink.y + glyph_ink.height + geometry->y_offset) - new_y;
ink_rect->y = new_y;
}
}
if (logical_rect)
{
logical_rect->width += geometry->width;
if (i == start)
{
logical_rect->y = glyph_logical.y;
logical_rect->height = glyph_logical.height;
}
else
{
int new_y = MIN (logical_rect->y, glyph_logical.y);
logical_rect->height = MAX (logical_rect->y + logical_rect->height,
glyph_logical.y + glyph_logical.height) - new_y;
logical_rect->y = new_y;
}
}
x_pos += geometry->width;
}
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_extents_range (PangoGlyphString *glyphs,
int start,
int end,
PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
int x_pos = 0;
int i;
/* Note that the handling of empty rectangles for ink
* and logical rectangles is different. A zero-height ink
* rectangle makes no contribution to the overall ink rect,
* while a zero-height logical rect still reserves horizontal
* width. Also, we may return zero-width, positive height
* logical rectangles, while we'll never do that for the
* ink rect.
*/
g_return_if_fail (start <= end);
if (G_UNLIKELY (!ink_rect && !logical_rect))
return;
if (ink_rect)
{
ink_rect->x = 0;
ink_rect->y = 0;
ink_rect->width = 0;
ink_rect->height = 0;
}
if (logical_rect)
{
logical_rect->x = 0;
logical_rect->y = 0;
logical_rect->width = 0;
logical_rect->height = 0;
}
for (i = start; i < end; i++)
{
PangoRectangle glyph_ink;
PangoRectangle glyph_logical;
PangoGlyphGeometry *geometry = &glyphs->glyphs[i].geometry;
pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph,
ink_rect ? &glyph_ink : NULL,
logical_rect ? &glyph_logical : NULL);
if (ink_rect && glyph_ink.width != 0 && glyph_ink.height != 0)
{
if (ink_rect->width == 0 || ink_rect->height == 0)
{
ink_rect->x = x_pos + glyph_ink.x + geometry->x_offset;
ink_rect->width = glyph_ink.width;
ink_rect->y = glyph_ink.y + geometry->y_offset;
ink_rect->height = glyph_ink.height;
}
else
{
int new_x, new_y;
new_x = MIN (ink_rect->x, x_pos + glyph_ink.x + geometry->x_offset);
ink_rect->width = MAX (ink_rect->x + ink_rect->width,
x_pos + glyph_ink.x + glyph_ink.width + geometry->x_offset) - new_x;
ink_rect->x = new_x;
new_y = MIN (ink_rect->y, glyph_ink.y + geometry->y_offset);
ink_rect->height = MAX (ink_rect->y + ink_rect->height,
glyph_ink.y + glyph_ink.height + geometry->y_offset) - new_y;
ink_rect->y = new_y;
}
}
if (logical_rect)
{
logical_rect->width += geometry->width;
if (i == start)
{
logical_rect->y = glyph_logical.y;
logical_rect->height = glyph_logical.height;
}
else
{
int new_y = MIN (logical_rect->y, glyph_logical.y);
logical_rect->height = MAX (logical_rect->y + logical_rect->height,
glyph_logical.y + glyph_logical.height) - new_y;
logical_rect->y = new_y;
}
}
x_pos += geometry->width;
}
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,518 | pango_glyph_string_free (PangoGlyphString *string)
{
if (string == NULL)
return;
g_free (string->glyphs);
g_free (string->log_clusters);
g_slice_free (PangoGlyphString, string);
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_free (PangoGlyphString *string)
{
if (string == NULL)
return;
g_free (string->glyphs);
g_free (string->log_clusters);
g_slice_free (PangoGlyphString, string);
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,519 | pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
const char *text,
int length,
int embedding_level,
int *logical_widths)
{
/* Build a PangoGlyphItem so we can use PangoGlyphItemIter.
* This API should have been made to take a PangoGlyphItem... */
PangoItem item = {0, length, g_utf8_strlen (text, length),
{NULL, NULL, NULL,
embedding_level, PANGO_GRAVITY_AUTO, 0,
PANGO_SCRIPT_UNKNOWN, NULL,
NULL}};
PangoGlyphItem glyph_item = {&item, glyphs};
PangoGlyphItemIter iter;
gboolean has_cluster;
int dir;
dir = embedding_level % 2 == 0 ? +1 : -1;
for (has_cluster = pango_glyph_item_iter_init_start (&iter, &glyph_item, text);
has_cluster;
has_cluster = pango_glyph_item_iter_next_cluster (&iter))
{
int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
for (glyph_index = iter.start_glyph;
glyph_index != iter.end_glyph;
glyph_index += dir)
{
cluster_width += glyphs->glyphs[glyph_index].geometry.width;
}
num_chars = iter.end_char - iter.start_char;
if (num_chars) /* pedantic */
{
char_width = cluster_width / num_chars;
for (char_index = iter.start_char;
char_index < iter.end_char;
char_index++)
{
logical_widths[char_index] = char_width;
}
/* add any residues to the first char */
logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
}
}
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
const char *text,
int length,
int embedding_level,
int *logical_widths)
{
/* Build a PangoGlyphItem so we can use PangoGlyphItemIter.
* This API should have been made to take a PangoGlyphItem... */
PangoItem item = {0, length, g_utf8_strlen (text, length),
{NULL, NULL, NULL,
embedding_level, PANGO_GRAVITY_AUTO, 0,
PANGO_SCRIPT_UNKNOWN, NULL,
NULL}};
PangoGlyphItem glyph_item = {&item, glyphs};
PangoGlyphItemIter iter;
gboolean has_cluster;
int dir;
dir = embedding_level % 2 == 0 ? +1 : -1;
for (has_cluster = pango_glyph_item_iter_init_start (&iter, &glyph_item, text);
has_cluster;
has_cluster = pango_glyph_item_iter_next_cluster (&iter))
{
int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
for (glyph_index = iter.start_glyph;
glyph_index != iter.end_glyph;
glyph_index += dir)
{
cluster_width += glyphs->glyphs[glyph_index].geometry.width;
}
num_chars = iter.end_char - iter.start_char;
if (num_chars) /* pedantic */
{
char_width = cluster_width / num_chars;
for (char_index = iter.start_char;
char_index < iter.end_char;
char_index++)
{
logical_widths[char_index] = char_width;
}
/* add any residues to the first char */
logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
}
}
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,520 | pango_glyph_string_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
our_type = g_boxed_type_register_static (I_("PangoGlyphString"),
(GBoxedCopyFunc)pango_glyph_string_copy,
(GBoxedFreeFunc)pango_glyph_string_free);
return our_type;
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
our_type = g_boxed_type_register_static (I_("PangoGlyphString"),
(GBoxedCopyFunc)pango_glyph_string_copy,
(GBoxedFreeFunc)pango_glyph_string_free);
return our_type;
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,521 | pango_glyph_string_get_width (PangoGlyphString *glyphs)
{
int i;
int width = 0;
for (i = 0; i < glyphs->num_glyphs; i++)
width += glyphs->glyphs[i].geometry.width;
return width;
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_get_width (PangoGlyphString *glyphs)
{
int i;
int width = 0;
for (i = 0; i < glyphs->num_glyphs; i++)
width += glyphs->glyphs[i].geometry.width;
return width;
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,522 | pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
char *text,
int length,
PangoAnalysis *analysis,
int index,
gboolean trailing,
int *x_pos)
{
int i;
int start_xpos = 0;
int end_xpos = 0;
int width = 0;
int start_index = -1;
int end_index = -1;
int cluster_chars = 0;
int cluster_offset = 0;
char *p;
g_return_if_fail (glyphs != NULL);
g_return_if_fail (length >= 0);
g_return_if_fail (length == 0 || text != NULL);
if (!x_pos) /* Allow the user to do the useless */
return;
if (glyphs->num_glyphs == 0)
{
*x_pos = 0;
return;
}
/* Calculate the starting and ending character positions
* and x positions for the cluster
*/
if (analysis->level % 2) /* Right to left */
{
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
width += glyphs->glyphs[i].geometry.width;
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
if (glyphs->log_clusters[i] > index)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
if (glyphs->log_clusters[i] != start_index)
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
width -= glyphs->glyphs[i].geometry.width;
}
}
else /* Left to right */
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
if (glyphs->log_clusters[i] > index)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
if (glyphs->log_clusters[i] != start_index)
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
width += glyphs->glyphs[i].geometry.width;
}
}
if (end_index == -1)
{
end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
/* Calculate offset of character within cluster */
p = text + start_index;
while (p < text + end_index)
{
if (p < text + index)
cluster_offset++;
cluster_chars++;
p = g_utf8_next_char (p);
}
if (trailing)
cluster_offset += 1;
*x_pos = ((cluster_chars - cluster_offset) * start_xpos +
cluster_offset * end_xpos) / cluster_chars;
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
char *text,
int length,
PangoAnalysis *analysis,
int index,
gboolean trailing,
int *x_pos)
{
int i;
int start_xpos = 0;
int end_xpos = 0;
int width = 0;
int start_index = -1;
int end_index = -1;
int cluster_chars = 0;
int cluster_offset = 0;
char *p;
g_return_if_fail (glyphs != NULL);
g_return_if_fail (length >= 0);
g_return_if_fail (length == 0 || text != NULL);
if (!x_pos) /* Allow the user to do the useless */
return;
if (glyphs->num_glyphs == 0)
{
*x_pos = 0;
return;
}
/* Calculate the starting and ending character positions
* and x positions for the cluster
*/
if (analysis->level % 2) /* Right to left */
{
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
width += glyphs->glyphs[i].geometry.width;
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
if (glyphs->log_clusters[i] > index)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
if (glyphs->log_clusters[i] != start_index)
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
width -= glyphs->glyphs[i].geometry.width;
}
}
else /* Left to right */
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
if (glyphs->log_clusters[i] > index)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
if (glyphs->log_clusters[i] != start_index)
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
width += glyphs->glyphs[i].geometry.width;
}
}
if (end_index == -1)
{
end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
/* Calculate offset of character within cluster */
p = text + start_index;
while (p < text + end_index)
{
if (p < text + index)
cluster_offset++;
cluster_chars++;
p = g_utf8_next_char (p);
}
if (trailing)
cluster_offset += 1;
*x_pos = ((cluster_chars - cluster_offset) * start_xpos +
cluster_offset * end_xpos) / cluster_chars;
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,523 | pango_glyph_string_new (void)
{
PangoGlyphString *string = g_slice_new (PangoGlyphString);
string->num_glyphs = 0;
string->space = 0;
string->glyphs = NULL;
string->log_clusters = NULL;
return string;
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_new (void)
{
PangoGlyphString *string = g_slice_new (PangoGlyphString);
string->num_glyphs = 0;
string->space = 0;
string->glyphs = NULL;
string->log_clusters = NULL;
return string;
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,524 | pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
char *text,
int length,
PangoAnalysis *analysis,
int x_pos,
int *index,
gboolean *trailing)
{
int i;
int start_xpos = 0;
int end_xpos = 0;
int width = 0;
int start_index = -1;
int end_index = -1;
int cluster_chars = 0;
char *p;
gboolean found = FALSE;
/* Find the cluster containing the position */
width = 0;
if (analysis->level % 2) /* Right to left */
{
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
width += glyphs->glyphs[i].geometry.width;
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
width -= glyphs->glyphs[i].geometry.width;
if (width <= x_pos && x_pos < width + glyphs->glyphs[i].geometry.width)
found = TRUE;
}
}
else /* Left to right */
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
if (width <= x_pos && x_pos < width + glyphs->glyphs[i].geometry.width)
found = TRUE;
width += glyphs->glyphs[i].geometry.width;
}
}
if (end_index == -1)
{
end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
/* Calculate number of chars within cluster */
p = text + start_index;
while (p < text + end_index)
{
p = g_utf8_next_char (p);
cluster_chars++;
}
if (start_xpos == end_xpos)
{
if (index)
*index = start_index;
if (trailing)
*trailing = FALSE;
}
else
{
double cp = ((double)(x_pos - start_xpos) * cluster_chars) / (end_xpos - start_xpos);
/* LTR and right-to-left have to be handled separately
* here because of the edge condition when we are exactly
* at a pixel boundary; end_xpos goes with the next
* character for LTR, with the previous character for RTL.
*/
if (start_xpos < end_xpos) /* Left-to-right */
{
if (index)
{
char *p = text + start_index;
int i = 0;
while (i + 1 <= cp)
{
p = g_utf8_next_char (p);
i++;
}
*index = (p - text);
}
if (trailing)
*trailing = (cp - (int)cp >= 0.5) ? TRUE : FALSE;
}
else /* Right-to-left */
{
if (index)
{
char *p = text + start_index;
int i = 0;
while (i + 1 < cp)
{
p = g_utf8_next_char (p);
i++;
}
*index = (p - text);
}
if (trailing)
{
double cp_flip = cluster_chars - cp;
*trailing = (cp_flip - (int)cp_flip >= 0.5) ? FALSE : TRUE;
}
}
}
}
| DoS Exec Code Overflow | 0 | pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
char *text,
int length,
PangoAnalysis *analysis,
int x_pos,
int *index,
gboolean *trailing)
{
int i;
int start_xpos = 0;
int end_xpos = 0;
int width = 0;
int start_index = -1;
int end_index = -1;
int cluster_chars = 0;
char *p;
gboolean found = FALSE;
/* Find the cluster containing the position */
width = 0;
if (analysis->level % 2) /* Right to left */
{
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
width += glyphs->glyphs[i].geometry.width;
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
width -= glyphs->glyphs[i].geometry.width;
if (width <= x_pos && x_pos < width + glyphs->glyphs[i].geometry.width)
found = TRUE;
}
}
else /* Left to right */
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
if (width <= x_pos && x_pos < width + glyphs->glyphs[i].geometry.width)
found = TRUE;
width += glyphs->glyphs[i].geometry.width;
}
}
if (end_index == -1)
{
end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
/* Calculate number of chars within cluster */
p = text + start_index;
while (p < text + end_index)
{
p = g_utf8_next_char (p);
cluster_chars++;
}
if (start_xpos == end_xpos)
{
if (index)
*index = start_index;
if (trailing)
*trailing = FALSE;
}
else
{
double cp = ((double)(x_pos - start_xpos) * cluster_chars) / (end_xpos - start_xpos);
/* LTR and right-to-left have to be handled separately
* here because of the edge condition when we are exactly
* at a pixel boundary; end_xpos goes with the next
* character for LTR, with the previous character for RTL.
*/
if (start_xpos < end_xpos) /* Left-to-right */
{
if (index)
{
char *p = text + start_index;
int i = 0;
while (i + 1 <= cp)
{
p = g_utf8_next_char (p);
i++;
}
*index = (p - text);
}
if (trailing)
*trailing = (cp - (int)cp >= 0.5) ? TRUE : FALSE;
}
else /* Right-to-left */
{
if (index)
{
char *p = text + start_index;
int i = 0;
while (i + 1 < cp)
{
p = g_utf8_next_char (p);
i++;
}
*index = (p - text);
}
if (trailing)
{
double cp_flip = cluster_chars - cp;
*trailing = (cp_flip - (int)cp_flip >= 0.5) ? FALSE : TRUE;
}
}
}
}
| @@ -61,14 +61,28 @@ pango_glyph_string_set_size (PangoGlyphString *string, gint new_len)
while (new_len > string->space)
{
if (string->space == 0)
- string->space = 1;
+ {
+ string->space = 4;
+ }
else
- string->space *= 2;
-
- if (string->space < 0)
{
- g_warning ("glyph string length overflows maximum integer size, truncated");
- new_len = string->space = G_MAXINT - 8;
+ const guint max_space =
+ MIN (G_MAXINT, G_MAXSIZE / MAX (sizeof(PangoGlyphInfo), sizeof(gint)));
+
+ guint more_space = (guint)string->space * 2;
+
+ if (more_space > max_space)
+ {
+ more_space = max_space;
+
+ if ((guint)new_len > max_space)
+ {
+ g_error ("%s: failed to allocate glyph string of length %i\n",
+ G_STRLOC, new_len);
+ }
+ }
+
+ string->space = more_space;
}
}
| CWE-189 | null | null |
14,525 | _skip(conn c, int n, const char *line, int len)
{
/* Invert the meaning of in_job_read while throwing away data -- it
* counts the bytes that remain to be thrown away. */
c->in_job = 0;
c->in_job_read = n;
fill_extra_data(c);
if (c->in_job_read == 0) return reply(c, line, len, STATE_SENDWORD);
c->reply = line;
c->reply_len = len;
c->reply_sent = 0;
c->state = STATE_BITBUCKET;
return;
}
| Exec Code | 0 | _skip(conn c, int n, const char *line, int len)
{
/* Invert the meaning of in_job_read while throwing away data -- it
* counts the bytes that remain to be thrown away. */
c->in_job = 0;
c->in_job_read = n;
fill_extra_data(c);
if (c->in_job_read == 0) return reply(c, line, len, STATE_SENDWORD);
c->reply = line;
c->reply_len = len;
c->reply_sent = 0;
c->state = STATE_BITBUCKET;
return;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,526 | buried_job_p(tube t)
{
return job_list_any_p(&t->buried);
}
| Exec Code | 0 | buried_job_p(tube t)
{
return job_list_any_p(&t->buried);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,527 | cmd_len(conn c)
{
return scan_line_end(c->cmd, c->cmd_read);
}
| Exec Code | 0 | cmd_len(conn c)
{
return scan_line_end(c->cmd, c->cmd_read);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,528 | delay_q_take()
{
job j = delay_q_peek();
return j ? pq_take(&j->tube->delay) : NULL;
}
| Exec Code | 0 | delay_q_take()
{
job j = delay_q_peek();
return j ? pq_take(&j->tube->delay) : NULL;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,529 | do_cmd(conn c)
{
dispatch_cmd(c);
fill_extra_data(c);
}
| Exec Code | 0 | do_cmd(conn c)
{
dispatch_cmd(c);
fill_extra_data(c);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,530 | do_list_tubes(conn c, ms l)
{
char *buf;
tube t;
size_t i, resp_z;
/* first, measure how big a buffer we will need */
resp_z = 6; /* initial "---\n" and final "\r\n" */
for (i = 0; i < l->used; i++) {
t = l->items[i];
resp_z += 3 + strlen(t->name); /* including "- " and "\n" */
}
c->out_job = allocate_job(resp_z); /* fake job to hold response data */
if (!c->out_job) return reply_serr(c, MSG_OUT_OF_MEMORY);
/* Mark this job as a copy so it can be appropriately freed later on */
c->out_job->state = JOB_STATE_COPY;
/* now actually format the response */
buf = c->out_job->body;
buf += snprintf(buf, 5, "---\n");
for (i = 0; i < l->used; i++) {
t = l->items[i];
buf += snprintf(buf, 4 + strlen(t->name), "- %s\n", t->name);
}
buf[0] = '\r';
buf[1] = '\n';
c->out_job_sent = 0;
return reply_line(c, STATE_SENDJOB, "OK %d\r\n", resp_z - 2);
}
| Exec Code | 0 | do_list_tubes(conn c, ms l)
{
char *buf;
tube t;
size_t i, resp_z;
/* first, measure how big a buffer we will need */
resp_z = 6; /* initial "---\n" and final "\r\n" */
for (i = 0; i < l->used; i++) {
t = l->items[i];
resp_z += 3 + strlen(t->name); /* including "- " and "\n" */
}
c->out_job = allocate_job(resp_z); /* fake job to hold response data */
if (!c->out_job) return reply_serr(c, MSG_OUT_OF_MEMORY);
/* Mark this job as a copy so it can be appropriately freed later on */
c->out_job->state = JOB_STATE_COPY;
/* now actually format the response */
buf = c->out_job->body;
buf += snprintf(buf, 5, "---\n");
for (i = 0; i < l->used; i++) {
t = l->items[i];
buf += snprintf(buf, 4 + strlen(t->name), "- %s\n", t->name);
}
buf[0] = '\r';
buf[1] = '\n';
c->out_job_sent = 0;
return reply_line(c, STATE_SENDJOB, "OK %d\r\n", resp_z - 2);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,531 | do_stats(conn c, fmt_fn fmt, void *data)
{
int r, stats_len;
/* first, measure how big a buffer we will need */
stats_len = fmt(NULL, 0, data) + 16;
c->out_job = allocate_job(stats_len); /* fake job to hold stats data */
if (!c->out_job) return reply_serr(c, MSG_OUT_OF_MEMORY);
/* Mark this job as a copy so it can be appropriately freed later on */
c->out_job->state = JOB_STATE_COPY;
/* now actually format the stats data */
r = fmt(c->out_job->body, stats_len, data);
/* and set the actual body size */
c->out_job->body_size = r;
if (r > stats_len) return reply_serr(c, MSG_INTERNAL_ERROR);
c->out_job_sent = 0;
return reply_line(c, STATE_SENDJOB, "OK %d\r\n", r - 2);
}
| Exec Code | 0 | do_stats(conn c, fmt_fn fmt, void *data)
{
int r, stats_len;
/* first, measure how big a buffer we will need */
stats_len = fmt(NULL, 0, data) + 16;
c->out_job = allocate_job(stats_len); /* fake job to hold stats data */
if (!c->out_job) return reply_serr(c, MSG_OUT_OF_MEMORY);
/* Mark this job as a copy so it can be appropriately freed later on */
c->out_job->state = JOB_STATE_COPY;
/* now actually format the stats data */
r = fmt(c->out_job->body, stats_len, data);
/* and set the actual body size */
c->out_job->body_size = r;
if (r > stats_len) return reply_serr(c, MSG_INTERNAL_ERROR);
c->out_job_sent = 0;
return reply_line(c, STATE_SENDJOB, "OK %d\r\n", r - 2);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,532 | enqueue_job(job j, usec delay, char update_store)
{
int r;
j->reserver = NULL;
if (delay) {
j->deadline_at = now_usec() + delay;
r = pq_give(&j->tube->delay, j);
if (!r) return 0;
j->state = JOB_STATE_DELAYED;
set_main_delay_timeout();
} else {
r = pq_give(&j->tube->ready, j);
if (!r) return 0;
j->state = JOB_STATE_READY;
ready_ct++;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct++;
j->tube->stat.urgent_ct++;
}
}
if (update_store) {
r = binlog_write_job(j);
if (!r) return -1;
}
process_queue();
return 1;
}
| Exec Code | 0 | enqueue_job(job j, usec delay, char update_store)
{
int r;
j->reserver = NULL;
if (delay) {
j->deadline_at = now_usec() + delay;
r = pq_give(&j->tube->delay, j);
if (!r) return 0;
j->state = JOB_STATE_DELAYED;
set_main_delay_timeout();
} else {
r = pq_give(&j->tube->ready, j);
if (!r) return 0;
j->state = JOB_STATE_READY;
ready_ct++;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct++;
j->tube->stat.urgent_ct++;
}
}
if (update_store) {
r = binlog_write_job(j);
if (!r) return -1;
}
process_queue();
return 1;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,533 | enqueue_waiting_conn(conn c)
{
tube t;
size_t i;
global_stat.waiting_ct++;
c->type |= CONN_TYPE_WAITING;
for (i = 0; i < c->watch.used; i++) {
t = c->watch.items[i];
t->stat.waiting_ct++;
ms_append(&t->waiting, c);
}
}
| Exec Code | 0 | enqueue_waiting_conn(conn c)
{
tube t;
size_t i;
global_stat.waiting_ct++;
c->type |= CONN_TYPE_WAITING;
for (i = 0; i < c->watch.used; i++) {
t = c->watch.items[i];
t->stat.waiting_ct++;
ms_append(&t->waiting, c);
}
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,534 | enter_drain_mode(int sig)
{
drain_mode = 1;
}
| Exec Code | 0 | enter_drain_mode(int sig)
{
drain_mode = 1;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,535 | fill_extra_data(conn c)
{
int extra_bytes, job_data_bytes = 0, cmd_bytes;
if (!c->fd) return; /* the connection was closed */
if (!c->cmd_len) return; /* we don't have a complete command */
/* how many extra bytes did we read? */
extra_bytes = c->cmd_read - c->cmd_len;
/* how many bytes should we put into the job body? */
if (c->in_job) {
job_data_bytes = min(extra_bytes, c->in_job->body_size);
memcpy(c->in_job->body, c->cmd + c->cmd_len, job_data_bytes);
c->in_job_read = job_data_bytes;
} else if (c->in_job_read) {
/* we are in bit-bucket mode, throwing away data */
job_data_bytes = min(extra_bytes, c->in_job_read);
c->in_job_read -= job_data_bytes;
}
/* how many bytes are left to go into the future cmd? */
cmd_bytes = extra_bytes - job_data_bytes;
memmove(c->cmd, c->cmd + c->cmd_len + job_data_bytes, cmd_bytes);
c->cmd_read = cmd_bytes;
c->cmd_len = 0; /* we no longer know the length of the new command */
}
| Exec Code | 0 | fill_extra_data(conn c)
{
int extra_bytes, job_data_bytes = 0, cmd_bytes;
if (!c->fd) return; /* the connection was closed */
if (!c->cmd_len) return; /* we don't have a complete command */
/* how many extra bytes did we read? */
extra_bytes = c->cmd_read - c->cmd_len;
/* how many bytes should we put into the job body? */
if (c->in_job) {
job_data_bytes = min(extra_bytes, c->in_job->body_size);
memcpy(c->in_job->body, c->cmd + c->cmd_len, job_data_bytes);
c->in_job_read = job_data_bytes;
} else if (c->in_job_read) {
/* we are in bit-bucket mode, throwing away data */
job_data_bytes = min(extra_bytes, c->in_job_read);
c->in_job_read -= job_data_bytes;
}
/* how many bytes are left to go into the future cmd? */
cmd_bytes = extra_bytes - job_data_bytes;
memmove(c->cmd, c->cmd + c->cmd_len + job_data_bytes, cmd_bytes);
c->cmd_read = cmd_bytes;
c->cmd_len = 0; /* we no longer know the length of the new command */
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,536 | find_reserved_job_in_conn(conn c, job j)
{
return (j && j->reserver == c && j->state == JOB_STATE_RESERVED) ? j : NULL;
}
| Exec Code | 0 | find_reserved_job_in_conn(conn c, job j)
{
return (j && j->reserver == c && j->state == JOB_STATE_RESERVED) ? j : NULL;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,537 | fmt_job_stats(char *buf, size_t size, job j)
{
usec t;
uint64_t time_left;
t = now_usec();
if (j->state == JOB_STATE_RESERVED || j->state == JOB_STATE_DELAYED) {
time_left = (j->deadline_at - t) / 1000000;
} else {
time_left = 0;
}
return snprintf(buf, size, STATS_JOB_FMT,
j->id,
j->tube->name,
job_state(j),
j->pri,
(t - j->created_at) / 1000000,
j->delay / 1000000,
j->ttr / 1000000,
time_left,
j->reserve_ct,
j->timeout_ct,
j->release_ct,
j->bury_ct,
j->kick_ct);
}
| Exec Code | 0 | fmt_job_stats(char *buf, size_t size, job j)
{
usec t;
uint64_t time_left;
t = now_usec();
if (j->state == JOB_STATE_RESERVED || j->state == JOB_STATE_DELAYED) {
time_left = (j->deadline_at - t) / 1000000;
} else {
time_left = 0;
}
return snprintf(buf, size, STATS_JOB_FMT,
j->id,
j->tube->name,
job_state(j),
j->pri,
(t - j->created_at) / 1000000,
j->delay / 1000000,
j->ttr / 1000000,
time_left,
j->reserve_ct,
j->timeout_ct,
j->release_ct,
j->bury_ct,
j->kick_ct);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,538 | fmt_stats_tube(char *buf, size_t size, tube t)
{
uint64_t time_left;
if (t->pause > 0) {
time_left = (t->deadline_at - now_usec()) / 1000000;
} else {
time_left = 0;
}
return snprintf(buf, size, STATS_TUBE_FMT,
t->name,
t->stat.urgent_ct,
t->ready.used,
t->stat.reserved_ct,
t->delay.used,
t->stat.buried_ct,
t->stat.total_jobs_ct,
t->using_ct,
t->watching_ct,
t->stat.waiting_ct,
t->stat.pause_ct,
t->pause / 1000000,
time_left);
}
| Exec Code | 0 | fmt_stats_tube(char *buf, size_t size, tube t)
{
uint64_t time_left;
if (t->pause > 0) {
time_left = (t->deadline_at - now_usec()) / 1000000;
} else {
time_left = 0;
}
return snprintf(buf, size, STATS_TUBE_FMT,
t->name,
t->stat.urgent_ct,
t->ready.used,
t->stat.reserved_ct,
t->delay.used,
t->stat.buried_ct,
t->stat.total_jobs_ct,
t->using_ct,
t->watching_ct,
t->stat.waiting_ct,
t->stat.pause_ct,
t->pause / 1000000,
time_left);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,539 | get_delayed_job_ct()
{
tube t;
size_t i;
unsigned int count = 0;
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
count += t->delay.used;
}
return count;
}
| Exec Code | 0 | get_delayed_job_ct()
{
tube t;
size_t i;
unsigned int count = 0;
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
count += t->delay.used;
}
return count;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,540 | h_accept(const int fd, const short which, struct event *ev)
{
conn c;
int cfd, flags, r;
socklen_t addrlen;
struct sockaddr_in6 addr;
if (which == EV_TIMEOUT) return h_delay();
addrlen = sizeof addr;
cfd = accept(fd, (struct sockaddr *)&addr, &addrlen);
if (cfd == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) twarn("accept()");
if (errno == EMFILE) brake();
return;
}
flags = fcntl(cfd, F_GETFL, 0);
if (flags < 0) return twarn("getting flags"), close(cfd), v();
r = fcntl(cfd, F_SETFL, flags | O_NONBLOCK);
if (r < 0) return twarn("setting O_NONBLOCK"), close(cfd), v();
c = make_conn(cfd, STATE_WANTCOMMAND, default_tube, default_tube);
if (!c) return twarnx("make_conn() failed"), close(cfd), brake();
dprintf("accepted conn, fd=%d\n", cfd);
r = conn_set_evq(c, EV_READ | EV_PERSIST, (evh) h_conn);
if (r == -1) return twarnx("conn_set_evq() failed"), close(cfd), brake();
}
| Exec Code | 0 | h_accept(const int fd, const short which, struct event *ev)
{
conn c;
int cfd, flags, r;
socklen_t addrlen;
struct sockaddr_in6 addr;
if (which == EV_TIMEOUT) return h_delay();
addrlen = sizeof addr;
cfd = accept(fd, (struct sockaddr *)&addr, &addrlen);
if (cfd == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) twarn("accept()");
if (errno == EMFILE) brake();
return;
}
flags = fcntl(cfd, F_GETFL, 0);
if (flags < 0) return twarn("getting flags"), close(cfd), v();
r = fcntl(cfd, F_SETFL, flags | O_NONBLOCK);
if (r < 0) return twarn("setting O_NONBLOCK"), close(cfd), v();
c = make_conn(cfd, STATE_WANTCOMMAND, default_tube, default_tube);
if (!c) return twarnx("make_conn() failed"), close(cfd), brake();
dprintf("accepted conn, fd=%d\n", cfd);
r = conn_set_evq(c, EV_READ | EV_PERSIST, (evh) h_conn);
if (r == -1) return twarnx("conn_set_evq() failed"), close(cfd), brake();
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,541 | h_conn(const int fd, const short which, conn c)
{
if (fd != c->fd) {
twarnx("Argh! event fd doesn't match conn fd.");
close(fd);
return conn_close(c);
}
switch (which) {
case EV_TIMEOUT:
h_conn_timeout(c);
event_add(&c->evq, NULL); /* seems to be necessary */
break;
case EV_READ:
/* fall through... */
case EV_WRITE:
/* fall through... */
default:
h_conn_data(c);
}
while (cmd_data_ready(c) && (c->cmd_len = cmd_len(c))) do_cmd(c);
}
| Exec Code | 0 | h_conn(const int fd, const short which, conn c)
{
if (fd != c->fd) {
twarnx("Argh! event fd doesn't match conn fd.");
close(fd);
return conn_close(c);
}
switch (which) {
case EV_TIMEOUT:
h_conn_timeout(c);
event_add(&c->evq, NULL); /* seems to be necessary */
break;
case EV_READ:
/* fall through... */
case EV_WRITE:
/* fall through... */
default:
h_conn_data(c);
}
while (cmd_data_ready(c) && (c->cmd_len = cmd_len(c))) do_cmd(c);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,542 | h_conn_data(conn c)
{
int r, to_read;
job j;
struct iovec iov[2];
switch (c->state) {
case STATE_WANTCOMMAND:
r = read(c->fd, c->cmd + c->cmd_read, LINE_BUF_SIZE - c->cmd_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->cmd_read += r; /* we got some bytes */
c->cmd_len = cmd_len(c); /* find the EOL */
/* yay, complete command line */
if (c->cmd_len) return do_cmd(c);
/* c->cmd_read > LINE_BUF_SIZE can't happen */
/* command line too long? */
if (c->cmd_read == LINE_BUF_SIZE) {
c->cmd_read = 0; /* discard the input so far */
return reply_msg(c, MSG_BAD_FORMAT);
}
/* otherwise we have an incomplete line, so just keep waiting */
break;
case STATE_BITBUCKET:
/* Invert the meaning of in_job_read while throwing away data -- it
* counts the bytes that remain to be thrown away. */
to_read = min(c->in_job_read, BUCKET_BUF_SIZE);
r = read(c->fd, bucket, to_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->in_job_read -= r; /* we got some bytes */
/* (c->in_job_read < 0) can't happen */
if (c->in_job_read == 0) {
return reply(c, c->reply, c->reply_len, STATE_SENDWORD);
}
break;
case STATE_WANTDATA:
j = c->in_job;
r = read(c->fd, j->body + c->in_job_read, j->body_size -c->in_job_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->in_job_read += r; /* we got some bytes */
/* (j->in_job_read > j->body_size) can't happen */
maybe_enqueue_incoming_job(c);
break;
case STATE_SENDWORD:
r= write(c->fd, c->reply + c->reply_sent, c->reply_len - c->reply_sent);
if (r == -1) return check_err(c, "write()");
if (r == 0) return conn_close(c); /* the client hung up */
c->reply_sent += r; /* we got some bytes */
/* (c->reply_sent > c->reply_len) can't happen */
if (c->reply_sent == c->reply_len) return reset_conn(c);
/* otherwise we sent an incomplete reply, so just keep waiting */
break;
case STATE_SENDJOB:
j = c->out_job;
iov[0].iov_base = (void *)(c->reply + c->reply_sent);
iov[0].iov_len = c->reply_len - c->reply_sent; /* maybe 0 */
iov[1].iov_base = j->body + c->out_job_sent;
iov[1].iov_len = j->body_size - c->out_job_sent;
r = writev(c->fd, iov, 2);
if (r == -1) return check_err(c, "writev()");
if (r == 0) return conn_close(c); /* the client hung up */
/* update the sent values */
c->reply_sent += r;
if (c->reply_sent >= c->reply_len) {
c->out_job_sent += c->reply_sent - c->reply_len;
c->reply_sent = c->reply_len;
}
/* (c->out_job_sent > j->body_size) can't happen */
/* are we done? */
if (c->out_job_sent == j->body_size) return reset_conn(c);
/* otherwise we sent incomplete data, so just keep waiting */
break;
case STATE_WAIT: /* keep an eye out in case they hang up */
/* but don't hang up just because our buffer is full */
if (LINE_BUF_SIZE - c->cmd_read < 1) break;
r = read(c->fd, c->cmd + c->cmd_read, LINE_BUF_SIZE - c->cmd_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->cmd_read += r; /* we got some bytes */
}
}
| Exec Code | 0 | h_conn_data(conn c)
{
int r, to_read;
job j;
struct iovec iov[2];
switch (c->state) {
case STATE_WANTCOMMAND:
r = read(c->fd, c->cmd + c->cmd_read, LINE_BUF_SIZE - c->cmd_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->cmd_read += r; /* we got some bytes */
c->cmd_len = cmd_len(c); /* find the EOL */
/* yay, complete command line */
if (c->cmd_len) return do_cmd(c);
/* c->cmd_read > LINE_BUF_SIZE can't happen */
/* command line too long? */
if (c->cmd_read == LINE_BUF_SIZE) {
c->cmd_read = 0; /* discard the input so far */
return reply_msg(c, MSG_BAD_FORMAT);
}
/* otherwise we have an incomplete line, so just keep waiting */
break;
case STATE_BITBUCKET:
/* Invert the meaning of in_job_read while throwing away data -- it
* counts the bytes that remain to be thrown away. */
to_read = min(c->in_job_read, BUCKET_BUF_SIZE);
r = read(c->fd, bucket, to_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->in_job_read -= r; /* we got some bytes */
/* (c->in_job_read < 0) can't happen */
if (c->in_job_read == 0) {
return reply(c, c->reply, c->reply_len, STATE_SENDWORD);
}
break;
case STATE_WANTDATA:
j = c->in_job;
r = read(c->fd, j->body + c->in_job_read, j->body_size -c->in_job_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->in_job_read += r; /* we got some bytes */
/* (j->in_job_read > j->body_size) can't happen */
maybe_enqueue_incoming_job(c);
break;
case STATE_SENDWORD:
r= write(c->fd, c->reply + c->reply_sent, c->reply_len - c->reply_sent);
if (r == -1) return check_err(c, "write()");
if (r == 0) return conn_close(c); /* the client hung up */
c->reply_sent += r; /* we got some bytes */
/* (c->reply_sent > c->reply_len) can't happen */
if (c->reply_sent == c->reply_len) return reset_conn(c);
/* otherwise we sent an incomplete reply, so just keep waiting */
break;
case STATE_SENDJOB:
j = c->out_job;
iov[0].iov_base = (void *)(c->reply + c->reply_sent);
iov[0].iov_len = c->reply_len - c->reply_sent; /* maybe 0 */
iov[1].iov_base = j->body + c->out_job_sent;
iov[1].iov_len = j->body_size - c->out_job_sent;
r = writev(c->fd, iov, 2);
if (r == -1) return check_err(c, "writev()");
if (r == 0) return conn_close(c); /* the client hung up */
/* update the sent values */
c->reply_sent += r;
if (c->reply_sent >= c->reply_len) {
c->out_job_sent += c->reply_sent - c->reply_len;
c->reply_sent = c->reply_len;
}
/* (c->out_job_sent > j->body_size) can't happen */
/* are we done? */
if (c->out_job_sent == j->body_size) return reset_conn(c);
/* otherwise we sent incomplete data, so just keep waiting */
break;
case STATE_WAIT: /* keep an eye out in case they hang up */
/* but don't hang up just because our buffer is full */
if (LINE_BUF_SIZE - c->cmd_read < 1) break;
r = read(c->fd, c->cmd + c->cmd_read, LINE_BUF_SIZE - c->cmd_read);
if (r == -1) return check_err(c, "read()");
if (r == 0) return conn_close(c); /* the client hung up */
c->cmd_read += r; /* we got some bytes */
}
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,543 | h_delay()
{
int r;
job j;
usec now;
int i;
tube t;
now = now_usec();
while ((j = delay_q_peek())) {
if (j->deadline_at > now) break;
j = delay_q_take();
r = enqueue_job(j, 0, 0);
if (r < 1) bury_job(j, 0); /* out of memory, so bury it */
}
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
dprintf("h_delay for %s t->waiting.used=%zu t->ready.used=%d t->pause=%" PRIu64 "\n",
t->name, t->waiting.used, t->ready.used, t->pause);
if (t->pause && t->deadline_at <= now) {
t->pause = 0;
process_queue();
}
}
set_main_delay_timeout();
}
| Exec Code | 0 | h_delay()
{
int r;
job j;
usec now;
int i;
tube t;
now = now_usec();
while ((j = delay_q_peek())) {
if (j->deadline_at > now) break;
j = delay_q_take();
r = enqueue_job(j, 0, 0);
if (r < 1) bury_job(j, 0); /* out of memory, so bury it */
}
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
dprintf("h_delay for %s t->waiting.used=%zu t->ready.used=%d t->pause=%" PRIu64 "\n",
t->name, t->waiting.used, t->ready.used, t->pause);
if (t->pause && t->deadline_at <= now) {
t->pause = 0;
process_queue();
}
}
set_main_delay_timeout();
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,544 | kick_buried_job(tube t)
{
int r;
job j;
size_t z;
if (!buried_job_p(t)) return 0;
j = remove_buried_job(t->buried.next);
z = binlog_reserve_space_update(j);
if (!z) return pq_give(&t->delay, j), 0; /* put it back */
j->reserved_binlog_space += z;
j->kick_ct++;
r = enqueue_job(j, 0, 1);
if (r == 1) return 1;
/* ready queue is full, so bury it */
bury_job(j, 0);
return 0;
}
| Exec Code | 0 | kick_buried_job(tube t)
{
int r;
job j;
size_t z;
if (!buried_job_p(t)) return 0;
j = remove_buried_job(t->buried.next);
z = binlog_reserve_space_update(j);
if (!z) return pq_give(&t->delay, j), 0; /* put it back */
j->reserved_binlog_space += z;
j->kick_ct++;
r = enqueue_job(j, 0, 1);
if (r == 1) return 1;
/* ready queue is full, so bury it */
bury_job(j, 0);
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,545 | kick_buried_jobs(tube t, unsigned int n)
{
unsigned int i;
for (i = 0; (i < n) && kick_buried_job(t); ++i);
return i;
}
| Exec Code | 0 | kick_buried_jobs(tube t, unsigned int n)
{
unsigned int i;
for (i = 0; (i < n) && kick_buried_job(t); ++i);
return i;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,546 | kick_delayed_job(tube t)
{
int r;
job j;
size_t z;
j = pq_take(&t->delay);
if (!j) return 0;
z = binlog_reserve_space_update(j);
if (!z) return pq_give(&t->delay, j), 0; /* put it back */
j->reserved_binlog_space += z;
j->kick_ct++;
r = enqueue_job(j, 0, 1);
if (r == 1) return 1;
/* ready queue is full, so delay it again */
r = enqueue_job(j, j->delay, 0);
if (r == 1) return 0;
/* last resort */
bury_job(j, 0);
return 0;
}
| Exec Code | 0 | kick_delayed_job(tube t)
{
int r;
job j;
size_t z;
j = pq_take(&t->delay);
if (!j) return 0;
z = binlog_reserve_space_update(j);
if (!z) return pq_give(&t->delay, j), 0; /* put it back */
j->reserved_binlog_space += z;
j->kick_ct++;
r = enqueue_job(j, 0, 1);
if (r == 1) return 1;
/* ready queue is full, so delay it again */
r = enqueue_job(j, j->delay, 0);
if (r == 1) return 0;
/* last resort */
bury_job(j, 0);
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,547 | kick_delayed_jobs(tube t, unsigned int n)
{
unsigned int i;
for (i = 0; (i < n) && kick_delayed_job(t); ++i);
return i;
}
| Exec Code | 0 | kick_delayed_jobs(tube t, unsigned int n)
{
unsigned int i;
for (i = 0; (i < n) && kick_delayed_job(t); ++i);
return i;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,548 | kick_jobs(tube t, unsigned int n)
{
if (buried_job_p(t)) return kick_buried_jobs(t, n);
return kick_delayed_jobs(t, n);
}
| Exec Code | 0 | kick_jobs(tube t, unsigned int n)
{
if (buried_job_p(t)) return kick_buried_jobs(t, n);
return kick_delayed_jobs(t, n);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,549 | maybe_enqueue_incoming_job(conn c)
{
job j = c->in_job;
/* do we have a complete job? */
if (c->in_job_read == j->body_size) return enqueue_incoming_job(c);
/* otherwise we have incomplete data, so just keep waiting */
c->state = STATE_WANTDATA;
}
| Exec Code | 0 | maybe_enqueue_incoming_job(conn c)
{
job j = c->in_job;
/* do we have a complete job? */
if (c->in_job_read == j->body_size) return enqueue_incoming_job(c);
/* otherwise we have incomplete data, so just keep waiting */
c->state = STATE_WANTDATA;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,550 | name_is_ok(const char *name, size_t max)
{
size_t len = strlen(name);
return len > 0 && len <= max &&
strspn(name, NAME_CHARS) == len && name[0] != '-';
}
| Exec Code | 0 | name_is_ok(const char *name, size_t max)
{
size_t len = strlen(name);
return len > 0 && len <= max &&
strspn(name, NAME_CHARS) == len && name[0] != '-';
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,551 | next_eligible_job(usec now)
{
tube t;
size_t i;
job j = NULL, candidate;
dprintf("tubes.used = %zu\n", tubes.used);
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
dprintf("for %s t->waiting.used=%zu t->ready.used=%d t->pause=%" PRIu64 "\n",
t->name, t->waiting.used, t->ready.used, t->pause);
if (t->pause) {
if (t->deadline_at > now) continue;
t->pause = 0;
}
if (t->waiting.used && t->ready.used) {
candidate = pq_peek(&t->ready);
if (!j || job_pri_cmp(candidate, j) < 0) j = candidate;
}
dprintf("i = %zu, tubes.used = %zu\n", i, tubes.used);
}
return j;
}
| Exec Code | 0 | next_eligible_job(usec now)
{
tube t;
size_t i;
job j = NULL, candidate;
dprintf("tubes.used = %zu\n", tubes.used);
for (i = 0; i < tubes.used; i++) {
t = tubes.items[i];
dprintf("for %s t->waiting.used=%zu t->ready.used=%d t->pause=%" PRIu64 "\n",
t->name, t->waiting.used, t->ready.used, t->pause);
if (t->pause) {
if (t->deadline_at > now) continue;
t->pause = 0;
}
if (t->waiting.used && t->ready.used) {
candidate = pq_peek(&t->ready);
if (!j || job_pri_cmp(candidate, j) < 0) j = candidate;
}
dprintf("i = %zu, tubes.used = %zu\n", i, tubes.used);
}
return j;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,552 | peek_job(uint64_t id)
{
return job_find(id);
}
| Exec Code | 0 | peek_job(uint64_t id)
{
return job_find(id);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,553 | process_queue()
{
job j;
usec now = now_usec();
dprintf("processing queue\n");
while ((j = next_eligible_job(now))) {
dprintf("got eligible job %llu in %s\n", j->id, j->tube->name);
j = pq_take(&j->tube->ready);
ready_ct--;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct--;
j->tube->stat.urgent_ct--;
}
reserve_job(remove_waiting_conn(ms_take(&j->tube->waiting)), j);
}
}
| Exec Code | 0 | process_queue()
{
job j;
usec now = now_usec();
dprintf("processing queue\n");
while ((j = next_eligible_job(now))) {
dprintf("got eligible job %llu in %s\n", j->id, j->tube->name);
j = pq_take(&j->tube->ready);
ready_ct--;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct--;
j->tube->stat.urgent_ct--;
}
reserve_job(remove_waiting_conn(ms_take(&j->tube->waiting)), j);
}
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,554 | prot_init()
{
started_at = now_usec();
memset(op_ct, 0, sizeof(op_ct));
ms_init(&tubes, NULL, NULL);
TUBE_ASSIGN(default_tube, tube_find_or_make("default"));
if (!default_tube) twarnx("Out of memory during startup!");
}
| Exec Code | 0 | prot_init()
{
started_at = now_usec();
memset(op_ct, 0, sizeof(op_ct));
ms_init(&tubes, NULL, NULL);
TUBE_ASSIGN(default_tube, tube_find_or_make("default"));
if (!default_tube) twarnx("Out of memory during startup!");
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,555 | prot_remove_tube(tube t)
{
ms_remove(&tubes, t);
}
| Exec Code | 0 | prot_remove_tube(tube t)
{
ms_remove(&tubes, t);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,556 | prot_replay_binlog(job binlog_jobs)
{
job j, nj;
usec delay;
int r;
for (j = binlog_jobs->next ; j != binlog_jobs ; j = nj) {
nj = j->next;
job_remove(j);
binlog_reserve_space_update(j); /* reserve space for a delete */
delay = 0;
switch (j->state) {
case JOB_STATE_BURIED:
bury_job(j, 0);
break;
case JOB_STATE_DELAYED:
if (started_at < j->deadline_at) {
delay = j->deadline_at - started_at;
}
/* fall through */
default:
r = enqueue_job(j, delay, 0);
if (r < 1) twarnx("error processing binlog job %llu", j->id);
}
}
}
| Exec Code | 0 | prot_replay_binlog(job binlog_jobs)
{
job j, nj;
usec delay;
int r;
for (j = binlog_jobs->next ; j != binlog_jobs ; j = nj) {
nj = j->next;
job_remove(j);
binlog_reserve_space_update(j); /* reserve space for a delete */
delay = 0;
switch (j->state) {
case JOB_STATE_BURIED:
bury_job(j, 0);
break;
case JOB_STATE_DELAYED:
if (started_at < j->deadline_at) {
delay = j->deadline_at - started_at;
}
/* fall through */
default:
r = enqueue_job(j, delay, 0);
if (r < 1) twarnx("error processing binlog job %llu", j->id);
}
}
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,557 | read_delay(usec *delay, const char *buf, char **end)
{
int r;
unsigned int delay_sec;
r = read_pri(&delay_sec, buf, end);
if (r) return r;
*delay = ((usec) delay_sec) * 1000000;
return 0;
}
| Exec Code | 0 | read_delay(usec *delay, const char *buf, char **end)
{
int r;
unsigned int delay_sec;
r = read_pri(&delay_sec, buf, end);
if (r) return r;
*delay = ((usec) delay_sec) * 1000000;
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,558 | read_pri(unsigned int *pri, const char *buf, char **end)
{
char *tend;
unsigned int tpri;
errno = 0;
while (buf[0] == ' ') buf++;
if (!isdigit(buf[0])) return -1;
tpri = strtoul(buf, &tend, 10);
if (tend == buf) return -1;
if (errno && errno != ERANGE) return -1;
if (!end && tend[0] != '\0') return -1;
if (pri) *pri = tpri;
if (end) *end = tend;
return 0;
}
| Exec Code | 0 | read_pri(unsigned int *pri, const char *buf, char **end)
{
char *tend;
unsigned int tpri;
errno = 0;
while (buf[0] == ' ') buf++;
if (!isdigit(buf[0])) return -1;
tpri = strtoul(buf, &tend, 10);
if (tend == buf) return -1;
if (errno && errno != ERANGE) return -1;
if (!end && tend[0] != '\0') return -1;
if (pri) *pri = tpri;
if (end) *end = tend;
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,559 | read_ttr(usec *ttr, const char *buf, char **end)
{
return read_delay(ttr, buf, end);
}
| Exec Code | 0 | read_ttr(usec *ttr, const char *buf, char **end)
{
return read_delay(ttr, buf, end);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,560 | read_tube_name(char **tubename, char *buf, char **end)
{
size_t len;
while (buf[0] == ' ') buf++;
len = strspn(buf, NAME_CHARS);
if (len == 0) return -1;
if (tubename) *tubename = buf;
if (end) *end = buf + len;
return 0;
}
| Exec Code | 0 | read_tube_name(char **tubename, char *buf, char **end)
{
size_t len;
while (buf[0] == ' ') buf++;
len = strspn(buf, NAME_CHARS);
if (len == 0) return -1;
if (tubename) *tubename = buf;
if (end) *end = buf + len;
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,561 | remove_buried_job(job j)
{
if (!j || j->state != JOB_STATE_BURIED) return NULL;
j = job_remove(j);
if (j) {
global_stat.buried_ct--;
j->tube->stat.buried_ct--;
}
return j;
}
| Exec Code | 0 | remove_buried_job(job j)
{
if (!j || j->state != JOB_STATE_BURIED) return NULL;
j = job_remove(j);
if (j) {
global_stat.buried_ct--;
j->tube->stat.buried_ct--;
}
return j;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,562 | remove_ready_job(job j)
{
if (!j || j->state != JOB_STATE_READY) return NULL;
j = pq_remove(&j->tube->ready, j);
if (j) {
ready_ct--;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct--;
j->tube->stat.urgent_ct--;
}
}
return j;
}
| Exec Code | 0 | remove_ready_job(job j)
{
if (!j || j->state != JOB_STATE_READY) return NULL;
j = pq_remove(&j->tube->ready, j);
if (j) {
ready_ct--;
if (j->pri < URGENT_THRESHOLD) {
global_stat.urgent_ct--;
j->tube->stat.urgent_ct--;
}
}
return j;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,563 | remove_reserved_job(conn c, job j)
{
return remove_this_reserved_job(c, find_reserved_job_in_conn(c, j));
}
| Exec Code | 0 | remove_reserved_job(conn c, job j)
{
return remove_this_reserved_job(c, find_reserved_job_in_conn(c, j));
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,564 | remove_waiting_conn(conn c)
{
tube t;
size_t i;
if (!conn_waiting(c)) return NULL;
c->type &= ~CONN_TYPE_WAITING;
global_stat.waiting_ct--;
for (i = 0; i < c->watch.used; i++) {
t = c->watch.items[i];
t->stat.waiting_ct--;
ms_remove(&t->waiting, c);
}
return c;
}
| Exec Code | 0 | remove_waiting_conn(conn c)
{
tube t;
size_t i;
if (!conn_waiting(c)) return NULL;
c->type &= ~CONN_TYPE_WAITING;
global_stat.waiting_ct--;
for (i = 0; i < c->watch.used; i++) {
t = c->watch.items[i];
t->stat.waiting_ct--;
ms_remove(&t->waiting, c);
}
return c;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,565 | reset_conn(conn c)
{
int r;
r = conn_update_evq(c, EV_READ | EV_PERSIST);
if (r == -1) return twarnx("update events failed"), conn_close(c);
/* was this a peek or stats command? */
if (c->out_job && c->out_job->state == JOB_STATE_COPY) job_free(c->out_job);
c->out_job = NULL;
c->reply_sent = 0; /* now that we're done, reset this */
c->state = STATE_WANTCOMMAND;
}
| Exec Code | 0 | reset_conn(conn c)
{
int r;
r = conn_update_evq(c, EV_READ | EV_PERSIST);
if (r == -1) return twarnx("update events failed"), conn_close(c);
/* was this a peek or stats command? */
if (c->out_job && c->out_job->state == JOB_STATE_COPY) job_free(c->out_job);
c->out_job = NULL;
c->reply_sent = 0; /* now that we're done, reset this */
c->state = STATE_WANTCOMMAND;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,566 | scan_line_end(const char *s, int size)
{
char *match;
match = memchr(s, '\r', size - 1);
if (!match) return 0;
/* this is safe because we only scan size - 1 chars above */
if (match[1] == '\n') return match - s + 2;
return 0;
}
| Exec Code | 0 | scan_line_end(const char *s, int size)
{
char *match;
match = memchr(s, '\r', size - 1);
if (!match) return 0;
/* this is safe because we only scan size - 1 chars above */
if (match[1] == '\n') return match - s + 2;
return 0;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,567 | set_main_delay_timeout()
{
job j = delay_q_peek();
tube t = pause_tube_peek();
usec deadline_at = t ? t->deadline_at : 0;
if (j && (!deadline_at || j->deadline_at < deadline_at)) deadline_at = j->deadline_at;
dprintf("deadline_at=%" PRIu64 "\n", deadline_at);
set_main_timeout(deadline_at);
}
| Exec Code | 0 | set_main_delay_timeout()
{
job j = delay_q_peek();
tube t = pause_tube_peek();
usec deadline_at = t ? t->deadline_at : 0;
if (j && (!deadline_at || j->deadline_at < deadline_at)) deadline_at = j->deadline_at;
dprintf("deadline_at=%" PRIu64 "\n", deadline_at);
set_main_timeout(deadline_at);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,568 | touch_job(conn c, job j)
{
j = find_reserved_job_in_conn(c, j);
if (j) {
j->deadline_at = now_usec() + j->ttr;
c->soonest_job = NULL;
}
return j;
}
| Exec Code | 0 | touch_job(conn c, job j)
{
j = find_reserved_job_in_conn(c, j);
if (j) {
j->deadline_at = now_usec() + j->ttr;
c->soonest_job = NULL;
}
return j;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,569 | wait_for_job(conn c, int timeout)
{
int r;
c->state = STATE_WAIT;
enqueue_waiting_conn(c);
/* Set the pending timeout to the requested timeout amount */
c->pending_timeout = timeout;
/* this conn is waiting, but we want to know if they hang up */
r = conn_update_evq(c, EV_READ | EV_PERSIST);
if (r == -1) return twarnx("update events failed"), conn_close(c);
}
| Exec Code | 0 | wait_for_job(conn c, int timeout)
{
int r;
c->state = STATE_WAIT;
enqueue_waiting_conn(c);
/* Set the pending timeout to the requested timeout amount */
c->pending_timeout = timeout;
/* this conn is waiting, but we want to know if they hang up */
r = conn_update_evq(c, EV_READ | EV_PERSIST);
if (r == -1) return twarnx("update events failed"), conn_close(c);
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,570 | which_cmd(conn c)
{
#define TEST_CMD(s,c,o) if (strncmp((s), (c), CONSTSTRLEN(c)) == 0) return (o);
TEST_CMD(c->cmd, CMD_PUT, OP_PUT);
TEST_CMD(c->cmd, CMD_PEEKJOB, OP_PEEKJOB);
TEST_CMD(c->cmd, CMD_PEEK_READY, OP_PEEK_READY);
TEST_CMD(c->cmd, CMD_PEEK_DELAYED, OP_PEEK_DELAYED);
TEST_CMD(c->cmd, CMD_PEEK_BURIED, OP_PEEK_BURIED);
TEST_CMD(c->cmd, CMD_RESERVE_TIMEOUT, OP_RESERVE_TIMEOUT);
TEST_CMD(c->cmd, CMD_RESERVE, OP_RESERVE);
TEST_CMD(c->cmd, CMD_DELETE, OP_DELETE);
TEST_CMD(c->cmd, CMD_RELEASE, OP_RELEASE);
TEST_CMD(c->cmd, CMD_BURY, OP_BURY);
TEST_CMD(c->cmd, CMD_KICK, OP_KICK);
TEST_CMD(c->cmd, CMD_TOUCH, OP_TOUCH);
TEST_CMD(c->cmd, CMD_JOBSTATS, OP_JOBSTATS);
TEST_CMD(c->cmd, CMD_STATS_TUBE, OP_STATS_TUBE);
TEST_CMD(c->cmd, CMD_STATS, OP_STATS);
TEST_CMD(c->cmd, CMD_USE, OP_USE);
TEST_CMD(c->cmd, CMD_WATCH, OP_WATCH);
TEST_CMD(c->cmd, CMD_IGNORE, OP_IGNORE);
TEST_CMD(c->cmd, CMD_LIST_TUBES_WATCHED, OP_LIST_TUBES_WATCHED);
TEST_CMD(c->cmd, CMD_LIST_TUBE_USED, OP_LIST_TUBE_USED);
TEST_CMD(c->cmd, CMD_LIST_TUBES, OP_LIST_TUBES);
TEST_CMD(c->cmd, CMD_QUIT, OP_QUIT);
TEST_CMD(c->cmd, CMD_PAUSE_TUBE, OP_PAUSE_TUBE);
return OP_UNKNOWN;
}
| Exec Code | 0 | which_cmd(conn c)
{
#define TEST_CMD(s,c,o) if (strncmp((s), (c), CONSTSTRLEN(c)) == 0) return (o);
TEST_CMD(c->cmd, CMD_PUT, OP_PUT);
TEST_CMD(c->cmd, CMD_PEEKJOB, OP_PEEKJOB);
TEST_CMD(c->cmd, CMD_PEEK_READY, OP_PEEK_READY);
TEST_CMD(c->cmd, CMD_PEEK_DELAYED, OP_PEEK_DELAYED);
TEST_CMD(c->cmd, CMD_PEEK_BURIED, OP_PEEK_BURIED);
TEST_CMD(c->cmd, CMD_RESERVE_TIMEOUT, OP_RESERVE_TIMEOUT);
TEST_CMD(c->cmd, CMD_RESERVE, OP_RESERVE);
TEST_CMD(c->cmd, CMD_DELETE, OP_DELETE);
TEST_CMD(c->cmd, CMD_RELEASE, OP_RELEASE);
TEST_CMD(c->cmd, CMD_BURY, OP_BURY);
TEST_CMD(c->cmd, CMD_KICK, OP_KICK);
TEST_CMD(c->cmd, CMD_TOUCH, OP_TOUCH);
TEST_CMD(c->cmd, CMD_JOBSTATS, OP_JOBSTATS);
TEST_CMD(c->cmd, CMD_STATS_TUBE, OP_STATS_TUBE);
TEST_CMD(c->cmd, CMD_STATS, OP_STATS);
TEST_CMD(c->cmd, CMD_USE, OP_USE);
TEST_CMD(c->cmd, CMD_WATCH, OP_WATCH);
TEST_CMD(c->cmd, CMD_IGNORE, OP_IGNORE);
TEST_CMD(c->cmd, CMD_LIST_TUBES_WATCHED, OP_LIST_TUBES_WATCHED);
TEST_CMD(c->cmd, CMD_LIST_TUBE_USED, OP_LIST_TUBE_USED);
TEST_CMD(c->cmd, CMD_LIST_TUBES, OP_LIST_TUBES);
TEST_CMD(c->cmd, CMD_QUIT, OP_QUIT);
TEST_CMD(c->cmd, CMD_PAUSE_TUBE, OP_PAUSE_TUBE);
return OP_UNKNOWN;
}
| @@ -1196,7 +1196,8 @@ dispatch_cmd(conn c)
if (errno) return reply_msg(c, MSG_BAD_FORMAT);
if (body_size > job_data_size_limit) {
- return reply_msg(c, MSG_JOB_TOO_BIG);
+ /* throw away the job body and respond with JOB_TOO_BIG */
+ return skip(c, body_size + 2, MSG_JOB_TOO_BIG);
}
/* don't allow trailing garbage */ | null | null | null |
14,571 | static GIOStatus irssi_ssl_close(GIOChannel *handle, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_close(handle, gerr);
}
| null | 0 | static GIOStatus irssi_ssl_close(GIOChannel *handle, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_close(handle, gerr);
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,572 | static GIOFlags irssi_ssl_get_flags(GIOChannel *handle)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_get_flags(handle);
}
| null | 0 | static GIOFlags irssi_ssl_get_flags(GIOChannel *handle)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_get_flags(handle);
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,573 | static gboolean irssi_ssl_init(void)
{
SSL_library_init();
SSL_load_error_strings();
ssl_ctx = SSL_CTX_new(SSLv23_client_method());
if(!ssl_ctx)
{
g_error("Initialization of the SSL library failed");
return FALSE;
}
return TRUE;
}
| null | 0 | static gboolean irssi_ssl_init(void)
{
SSL_library_init();
SSL_load_error_strings();
ssl_ctx = SSL_CTX_new(SSLv23_client_method());
if(!ssl_ctx)
{
g_error("Initialization of the SSL library failed");
return FALSE;
}
return TRUE;
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,574 | static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, gsize len, gsize *ret, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
gint ret1, err;
const char *errstr;
ret1 = SSL_read(chan->ssl, buf, len);
if(ret1 <= 0)
{
*ret = 0;
err = SSL_get_error(chan->ssl, ret1);
if(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
return G_IO_STATUS_AGAIN;
else if(err == SSL_ERROR_ZERO_RETURN)
return G_IO_STATUS_EOF;
else if (err == SSL_ERROR_SYSCALL)
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL && ret1 == -1)
errstr = strerror(errno);
if (errstr == NULL)
errstr = "server closed connection unexpectedly";
}
else
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL)
errstr = "unknown SSL error";
}
g_warning("SSL read error: %s", errstr);
*gerr = g_error_new_literal(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED,
errstr);
return G_IO_STATUS_ERROR;
}
else
{
*ret = ret1;
return G_IO_STATUS_NORMAL;
}
/*UNREACH*/
return G_IO_STATUS_ERROR;
}
| null | 0 | static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, gsize len, gsize *ret, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
gint ret1, err;
const char *errstr;
ret1 = SSL_read(chan->ssl, buf, len);
if(ret1 <= 0)
{
*ret = 0;
err = SSL_get_error(chan->ssl, ret1);
if(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
return G_IO_STATUS_AGAIN;
else if(err == SSL_ERROR_ZERO_RETURN)
return G_IO_STATUS_EOF;
else if (err == SSL_ERROR_SYSCALL)
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL && ret1 == -1)
errstr = strerror(errno);
if (errstr == NULL)
errstr = "server closed connection unexpectedly";
}
else
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL)
errstr = "unknown SSL error";
}
g_warning("SSL read error: %s", errstr);
*gerr = g_error_new_literal(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED,
errstr);
return G_IO_STATUS_ERROR;
}
else
{
*ret = ret1;
return G_IO_STATUS_NORMAL;
}
/*UNREACH*/
return G_IO_STATUS_ERROR;
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,575 | static GIOStatus irssi_ssl_seek(GIOChannel *handle, gint64 offset, GSeekType type, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_seek(handle, offset, type, gerr);
}
| null | 0 | static GIOStatus irssi_ssl_seek(GIOChannel *handle, gint64 offset, GSeekType type, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_seek(handle, offset, type, gerr);
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,576 | static GIOStatus irssi_ssl_set_flags(GIOChannel *handle, GIOFlags flags, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_set_flags(handle, flags, gerr);
}
| null | 0 | static GIOStatus irssi_ssl_set_flags(GIOChannel *handle, GIOFlags flags, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
return chan->giochan->funcs->io_set_flags(handle, flags, gerr);
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,577 | static GIOStatus irssi_ssl_write(GIOChannel *handle, const gchar *buf, gsize len, gsize *ret, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
gint ret1, err;
const char *errstr;
ret1 = SSL_write(chan->ssl, (const char *)buf, len);
if(ret1 <= 0)
{
*ret = 0;
err = SSL_get_error(chan->ssl, ret1);
if(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
return G_IO_STATUS_AGAIN;
else if(err == SSL_ERROR_ZERO_RETURN)
errstr = "server closed connection";
else if (err == SSL_ERROR_SYSCALL)
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL && ret1 == -1)
errstr = strerror(errno);
if (errstr == NULL)
errstr = "server closed connection unexpectedly";
}
else
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL)
errstr = "unknown SSL error";
}
g_warning("SSL write error: %s", errstr);
*gerr = g_error_new_literal(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED,
errstr);
return G_IO_STATUS_ERROR;
}
else
{
*ret = ret1;
return G_IO_STATUS_NORMAL;
}
/*UNREACH*/
return G_IO_STATUS_ERROR;
}
| null | 0 | static GIOStatus irssi_ssl_write(GIOChannel *handle, const gchar *buf, gsize len, gsize *ret, GError **gerr)
{
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
gint ret1, err;
const char *errstr;
ret1 = SSL_write(chan->ssl, (const char *)buf, len);
if(ret1 <= 0)
{
*ret = 0;
err = SSL_get_error(chan->ssl, ret1);
if(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
return G_IO_STATUS_AGAIN;
else if(err == SSL_ERROR_ZERO_RETURN)
errstr = "server closed connection";
else if (err == SSL_ERROR_SYSCALL)
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL && ret1 == -1)
errstr = strerror(errno);
if (errstr == NULL)
errstr = "server closed connection unexpectedly";
}
else
{
errstr = ERR_reason_error_string(ERR_get_error());
if (errstr == NULL)
errstr = "unknown SSL error";
}
g_warning("SSL write error: %s", errstr);
*gerr = g_error_new_literal(G_IO_CHANNEL_ERROR, G_IO_CHANNEL_ERROR_FAILED,
errstr);
return G_IO_STATUS_ERROR;
}
else
{
*ret = ret1;
return G_IO_STATUS_NORMAL;
}
/*UNREACH*/
return G_IO_STATUS_ERROR;
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,578 | GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
g_warning("Connection failed: SSL support not enabled in this build.");
errno = ENOSYS;
return NULL;
}
| null | 0 | GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
g_warning("Connection failed: SSL support not enabled in this build.");
errno = ENOSYS;
return NULL;
}
| @@ -26,6 +26,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -39,6 +40,7 @@ typedef struct
SSL *ssl;
SSL_CTX *ctx;
unsigned int verify:1;
+ const char *hostname;
} GIOSSLChannel;
static SSL_CTX *ssl_ctx = NULL;
@@ -53,7 +55,149 @@ static void irssi_ssl_free(GIOChannel *handle)
g_free(chan);
}
-static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
+/* Checks if the given string has internal NUL characters. */
+static gboolean has_internal_nul(const char* str, int len) {
+ /* Remove trailing nul characters. They would give false alarms */
+ while (len > 0 && str[len-1] == 0)
+ len--;
+ return strlen(str) != len;
+}
+
+/* tls_dns_name - Extract valid DNS name from subjectAltName value */
+static const char *tls_dns_name(const GENERAL_NAME * gn)
+{
+ const char *dnsname;
+
+ /* We expect the OpenSSL library to construct GEN_DNS extension objects as
+ ASN1_IA5STRING values. Check we got the right union member. */
+ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
+ g_warning("Invalid ASN1 value type in subjectAltName");
+ return NULL;
+ }
+
+ /* Safe to treat as an ASCII string possibly holding a DNS name */
+ dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
+
+ if (has_internal_nul(dnsname, ASN1_STRING_length(gn->d.ia5))) {
+ g_warning("Internal NUL in subjectAltName");
+ return NULL;
+ }
+
+ return dnsname;
+}
+
+/* tls_text_name - extract certificate property value by name */
+static char *tls_text_name(X509_NAME *name, int nid)
+{
+ int pos;
+ X509_NAME_ENTRY *entry;
+ ASN1_STRING *entry_str;
+ int utf8_length;
+ unsigned char *utf8_value;
+ char *result;
+
+ if (name == 0 || (pos = X509_NAME_get_index_by_NID(name, nid, -1)) < 0) {
+ return NULL;
+ }
+
+ entry = X509_NAME_get_entry(name, pos);
+ g_return_val_if_fail(entry != NULL, NULL);
+ entry_str = X509_NAME_ENTRY_get_data(entry);
+ g_return_val_if_fail(entry_str != NULL, NULL);
+
+ /* Convert everything into UTF-8. It's up to OpenSSL to do something
+ reasonable when converting ASCII formats that contain non-ASCII
+ content. */
+ if ((utf8_length = ASN1_STRING_to_UTF8(&utf8_value, entry_str)) < 0) {
+ g_warning("Error decoding ASN.1 type=%d", ASN1_STRING_type(entry_str));
+ return NULL;
+ }
+
+ if (has_internal_nul((char *)utf8_value, utf8_length)) {
+ g_warning("NUL character in hostname in certificate");
+ OPENSSL_free(utf8_value);
+ return NULL;
+ }
+
+ result = g_strdup((char *) utf8_value);
+ OPENSSL_free(utf8_value);
+ return result;
+}
+
+
+/** check if a hostname in the certificate matches the hostname we used for the connection */
+static gboolean match_hostname(const char *cert_hostname, const char *hostname)
+{
+ const char *hostname_left;
+
+ if (!strcasecmp(cert_hostname, hostname)) { /* exact match */
+ return TRUE;
+ } else if (cert_hostname[0] == '*' && cert_hostname[1] == '.' && cert_hostname[2] != 0) { /* wildcard match */
+ /* The initial '*' matches exactly one hostname component */
+ hostname_left = strchr(hostname, '.');
+ if (hostname_left != NULL && ! strcasecmp(hostname_left + 1, cert_hostname + 2)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* based on verify_extract_name from tls_client.c in postfix */
+static gboolean irssi_ssl_verify_hostname(X509 *cert, const char *hostname)
+{
+ int gen_index, gen_count;
+ gboolean matched = FALSE, has_dns_name = FALSE;
+ const char *cert_dns_name;
+ char *cert_subject_cn;
+ const GENERAL_NAME *gn;
+ STACK_OF(GENERAL_NAME) * gens;
+
+ /* Verify the dNSName(s) in the peer certificate against the hostname. */
+ gens = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0);
+ if (gens) {
+ gen_count = sk_GENERAL_NAME_num(gens);
+ for (gen_index = 0; gen_index < gen_count && !matched; ++gen_index) {
+ gn = sk_GENERAL_NAME_value(gens, gen_index);
+ if (gn->type != GEN_DNS)
+ continue;
+
+ /* Even if we have an invalid DNS name, we still ultimately
+ ignore the CommonName, because subjectAltName:DNS is
+ present (though malformed). */
+ has_dns_name = TRUE;
+ cert_dns_name = tls_dns_name(gn);
+ if (cert_dns_name && *cert_dns_name) {
+ matched = match_hostname(cert_dns_name, hostname);
+ }
+ }
+
+ /* Free stack *and* member GENERAL_NAME objects */
+ sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
+ }
+
+ if (has_dns_name) {
+ if (! matched) {
+ /* The CommonName in the issuer DN is obsolete when SubjectAltName is available. */
+ g_warning("None of the Subject Alt Names in the certificate match hostname '%s'", hostname);
+ }
+ return matched;
+ } else { /* No subjectAltNames, look at CommonName */
+ cert_subject_cn = tls_text_name(X509_get_subject_name(cert), NID_commonName);
+ if (cert_subject_cn && *cert_subject_cn) {
+ matched = match_hostname(cert_subject_cn, hostname);
+ if (! matched) {
+ g_warning("SSL certificate common name '%s' doesn't match host name '%s'", cert_subject_cn, hostname);
+ }
+ } else {
+ g_warning("No subjectAltNames and no valid common name in certificate");
+ }
+ free(cert_subject_cn);
+ }
+
+ return matched;
+}
+
+static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
if (SSL_get_verify_result(ssl) != X509_V_OK) {
unsigned char md[EVP_MAX_MD_SIZE];
@@ -89,6 +233,8 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
}
}
return FALSE;
+ } else if (! irssi_ssl_verify_hostname(cert, hostname)){
+ return FALSE;
}
return TRUE;
}
@@ -241,7 +387,7 @@ static gboolean irssi_ssl_init(void)
}
-static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
+static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
{
GIOSSLChannel *chan;
GIOChannel *gchan;
@@ -326,6 +472,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
chan->ssl = ssl;
chan->ctx = ctx;
chan->verify = verify;
+ chan->hostname = hostname;
gchan = (GIOChannel *)chan;
gchan->funcs = &irssi_ssl_channel_funcs;
@@ -336,14 +483,14 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycer
return gchan;
}
-GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
+GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
{
GIOChannel *handle, *ssl_handle;
handle = net_connect_ip(ip, port, my_ip);
if (handle == NULL)
return NULL;
- ssl_handle = irssi_ssl_get_iochannel(handle, cert, pkey, cafile, capath, verify);
+ ssl_handle = irssi_ssl_get_iochannel(handle, hostname, cert, pkey, cafile, capath, verify);
if (ssl_handle == NULL)
g_io_channel_unref(handle);
return ssl_handle;
@@ -385,7 +532,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
g_warning("SSL server supplied no certificate");
return -1;
}
- ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, cert);
+ ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, cert);
X509_free(cert);
return ret ? 0 : -1;
} | CWE-20 | null | null |
14,579 | SERVER_REC *cmd_options_get_server(const char *cmd,
GHashTable *optlist,
SERVER_REC *defserver)
{
SERVER_REC *server;
GSList *list, *tmp, *next;
/* get all the options, then remove the known ones. there should
be only one left - the server tag. */
list = hashtable_get_keys(optlist);
if (cmd != NULL) {
for (tmp = list; tmp != NULL; tmp = next) {
char *option = tmp->data;
next = tmp->next;
if (command_have_option(cmd, option))
list = g_slist_remove(list, option);
}
}
if (list == NULL)
return defserver;
server = server_find_tag(list->data);
if (server == NULL || list->next != NULL) {
/* unknown option (not server tag) */
signal_emit("error command", 2,
GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN),
server == NULL ? list->data : list->next->data);
signal_stop();
server = NULL;
}
g_slist_free(list);
return server;
}
| null | 0 | SERVER_REC *cmd_options_get_server(const char *cmd,
GHashTable *optlist,
SERVER_REC *defserver)
{
SERVER_REC *server;
GSList *list, *tmp, *next;
/* get all the options, then remove the known ones. there should
be only one left - the server tag. */
list = hashtable_get_keys(optlist);
if (cmd != NULL) {
for (tmp = list; tmp != NULL; tmp = next) {
char *option = tmp->data;
next = tmp->next;
if (command_have_option(cmd, option))
list = g_slist_remove(list, option);
}
}
if (list == NULL)
return defserver;
server = server_find_tag(list->data);
if (server == NULL || list->next != NULL) {
/* unknown option (not server tag) */
signal_emit("error command", 2,
GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN),
server == NULL ? list->data : list->next->data);
signal_stop();
server = NULL;
}
g_slist_free(list);
return server;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,580 | static void disconnect_servers(GSList *servers, int chat_type)
{
GSList *tmp, *next;
for (tmp = servers; tmp != NULL; tmp = next) {
SERVER_REC *rec = tmp->data;
next = tmp->next;
if (rec->chat_type == chat_type)
server_disconnect(rec);
}
}
| null | 0 | static void disconnect_servers(GSList *servers, int chat_type)
{
GSList *tmp, *next;
for (tmp = servers; tmp != NULL; tmp = next) {
SERVER_REC *rec = tmp->data;
next = tmp->next;
if (rec->chat_type == chat_type)
server_disconnect(rec);
}
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,581 | void server_change_nick(SERVER_REC *server, const char *nick)
{
g_free(server->nick);
server->nick = g_strdup(nick);
signal_emit("server nick changed", 1, server);
}
| null | 0 | void server_change_nick(SERVER_REC *server, const char *nick)
{
g_free(server->nick);
server->nick = g_strdup(nick);
signal_emit("server nick changed", 1, server);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,582 | SERVER_REC *server_connect(SERVER_CONNECT_REC *conn)
{
CHAT_PROTOCOL_REC *proto;
SERVER_REC *server;
proto = CHAT_PROTOCOL(conn);
server = proto->server_init_connect(conn);
proto->server_connect(server);
return server;
}
| null | 0 | SERVER_REC *server_connect(SERVER_CONNECT_REC *conn)
{
CHAT_PROTOCOL_REC *proto;
SERVER_REC *server;
proto = CHAT_PROTOCOL(conn);
server = proto->server_init_connect(conn);
proto->server_connect(server);
return server;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,583 | static void server_connect_callback_init(SERVER_REC *server, GIOChannel *handle)
{
int error;
g_return_if_fail(IS_SERVER(server));
error = net_geterror(handle);
if (error != 0) {
server->connection_lost = TRUE;
server_connect_failed(server, g_strerror(error));
return;
}
lookup_servers = g_slist_remove(lookup_servers, server);
g_source_remove(server->connect_tag);
server->connect_tag = -1;
server_connect_finished(server);
}
| null | 0 | static void server_connect_callback_init(SERVER_REC *server, GIOChannel *handle)
{
int error;
g_return_if_fail(IS_SERVER(server));
error = net_geterror(handle);
if (error != 0) {
server->connection_lost = TRUE;
server_connect_failed(server, g_strerror(error));
return;
}
lookup_servers = g_slist_remove(lookup_servers, server);
g_source_remove(server->connect_tag);
server->connect_tag = -1;
server_connect_finished(server);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,584 | static void server_connect_callback_init_ssl(SERVER_REC *server, GIOChannel *handle)
{
int error;
g_return_if_fail(IS_SERVER(server));
error = irssi_ssl_handshake(handle);
if (error == -1) {
server->connection_lost = TRUE;
server_connect_failed(server, NULL);
return;
}
if (error & 1) {
if (server->connect_tag != -1)
g_source_remove(server->connect_tag);
server->connect_tag = g_input_add(handle, error == 1 ? G_INPUT_READ : G_INPUT_WRITE,
(GInputFunction)
server_connect_callback_init_ssl,
server);
return;
}
lookup_servers = g_slist_remove(lookup_servers, server);
if (server->connect_tag != -1) {
g_source_remove(server->connect_tag);
server->connect_tag = -1;
}
server_connect_finished(server);
}
| null | 0 | static void server_connect_callback_init_ssl(SERVER_REC *server, GIOChannel *handle)
{
int error;
g_return_if_fail(IS_SERVER(server));
error = irssi_ssl_handshake(handle);
if (error == -1) {
server->connection_lost = TRUE;
server_connect_failed(server, NULL);
return;
}
if (error & 1) {
if (server->connect_tag != -1)
g_source_remove(server->connect_tag);
server->connect_tag = g_input_add(handle, error == 1 ? G_INPUT_READ : G_INPUT_WRITE,
(GInputFunction)
server_connect_callback_init_ssl,
server);
return;
}
lookup_servers = g_slist_remove(lookup_servers, server);
if (server->connect_tag != -1) {
g_source_remove(server->connect_tag);
server->connect_tag = -1;
}
server_connect_finished(server);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,585 | static void server_connect_callback_readpipe(SERVER_REC *server)
{
RESOLVED_IP_REC iprec;
IPADDR *ip;
const char *errormsg;
char *servername = NULL;
g_source_remove(server->connect_tag);
server->connect_tag = -1;
net_gethostbyname_return(server->connect_pipe[0], &iprec);
g_io_channel_close(server->connect_pipe[0]);
g_io_channel_unref(server->connect_pipe[0]);
g_io_channel_close(server->connect_pipe[1]);
g_io_channel_unref(server->connect_pipe[1]);
server->connect_pipe[0] = NULL;
server->connect_pipe[1] = NULL;
/* figure out if we should use IPv4 or v6 address */
if (iprec.error != 0) {
/* error */
ip = NULL;
} else if (server->connrec->family == AF_INET) {
/* force IPv4 connection */
ip = iprec.ip4.family == 0 ? NULL : &iprec.ip4;
servername = iprec.host4;
} else if (server->connrec->family == AF_INET6) {
/* force IPv6 connection */
ip = iprec.ip6.family == 0 ? NULL : &iprec.ip6;
servername = iprec.host6;
} else {
/* pick the one that was found, or if both do it like
/SET resolve_prefer_ipv6 says. */
if (iprec.ip4.family == 0 ||
(iprec.ip6.family != 0 &&
settings_get_bool("resolve_prefer_ipv6"))) {
ip = &iprec.ip6;
servername = iprec.host6;
} else {
ip = &iprec.ip4;
servername = iprec.host4;
}
}
if (ip != NULL) {
/* host lookup ok */
if (servername) {
g_free(server->connrec->address);
server->connrec->address = g_strdup(servername);
}
server_real_connect(server, ip, NULL);
errormsg = NULL;
} else {
if (iprec.error == 0 || net_hosterror_notfound(iprec.error)) {
/* IP wasn't found for the host, don't try to
reconnect back to this server */
server->dns_error = TRUE;
}
if (iprec.error == 0) {
/* forced IPv4 or IPv6 address but it wasn't found */
errormsg = server->connrec->family == AF_INET ?
"IPv4 address not found for host" :
"IPv6 address not found for host";
} else {
/* gethostbyname() failed */
errormsg = iprec.errorstr != NULL ? iprec.errorstr :
"Host lookup failed";
}
server->connection_lost = TRUE;
server_connect_failed(server, errormsg);
}
g_free(iprec.errorstr);
g_free(iprec.host4);
g_free(iprec.host6);
}
| null | 0 | static void server_connect_callback_readpipe(SERVER_REC *server)
{
RESOLVED_IP_REC iprec;
IPADDR *ip;
const char *errormsg;
char *servername = NULL;
g_source_remove(server->connect_tag);
server->connect_tag = -1;
net_gethostbyname_return(server->connect_pipe[0], &iprec);
g_io_channel_close(server->connect_pipe[0]);
g_io_channel_unref(server->connect_pipe[0]);
g_io_channel_close(server->connect_pipe[1]);
g_io_channel_unref(server->connect_pipe[1]);
server->connect_pipe[0] = NULL;
server->connect_pipe[1] = NULL;
/* figure out if we should use IPv4 or v6 address */
if (iprec.error != 0) {
/* error */
ip = NULL;
} else if (server->connrec->family == AF_INET) {
/* force IPv4 connection */
ip = iprec.ip4.family == 0 ? NULL : &iprec.ip4;
servername = iprec.host4;
} else if (server->connrec->family == AF_INET6) {
/* force IPv6 connection */
ip = iprec.ip6.family == 0 ? NULL : &iprec.ip6;
servername = iprec.host6;
} else {
/* pick the one that was found, or if both do it like
/SET resolve_prefer_ipv6 says. */
if (iprec.ip4.family == 0 ||
(iprec.ip6.family != 0 &&
settings_get_bool("resolve_prefer_ipv6"))) {
ip = &iprec.ip6;
servername = iprec.host6;
} else {
ip = &iprec.ip4;
servername = iprec.host4;
}
}
if (ip != NULL) {
/* host lookup ok */
if (servername) {
g_free(server->connrec->address);
server->connrec->address = g_strdup(servername);
}
server_real_connect(server, ip, NULL);
errormsg = NULL;
} else {
if (iprec.error == 0 || net_hosterror_notfound(iprec.error)) {
/* IP wasn't found for the host, don't try to
reconnect back to this server */
server->dns_error = TRUE;
}
if (iprec.error == 0) {
/* forced IPv4 or IPv6 address but it wasn't found */
errormsg = server->connrec->family == AF_INET ?
"IPv4 address not found for host" :
"IPv6 address not found for host";
} else {
/* gethostbyname() failed */
errormsg = iprec.errorstr != NULL ? iprec.errorstr :
"Host lookup failed";
}
server->connection_lost = TRUE;
server_connect_failed(server, errormsg);
}
g_free(iprec.errorstr);
g_free(iprec.host4);
g_free(iprec.host6);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,586 | void server_connect_finished(SERVER_REC *server)
{
server->connect_time = time(NULL);
servers = g_slist_append(servers, server);
signal_emit("server connected", 1, server);
}
| null | 0 | void server_connect_finished(SERVER_REC *server)
{
server->connect_time = time(NULL);
servers = g_slist_append(servers, server);
signal_emit("server connected", 1, server);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,587 | void server_connect_init(SERVER_REC *server)
{
const char *str;
g_return_if_fail(server != NULL);
MODULE_DATA_INIT(server);
server->type = module_get_uniq_id("SERVER", 0);
server_ref(server);
server->nick = g_strdup(server->connrec->nick);
if (server->connrec->username == NULL || *server->connrec->username == '\0') {
g_free_not_null(server->connrec->username);
str = g_get_user_name();
if (*str == '\0') str = "unknown";
server->connrec->username = g_strdup(str);
}
if (server->connrec->realname == NULL || *server->connrec->realname == '\0') {
g_free_not_null(server->connrec->realname);
str = g_get_real_name();
if (*str == '\0') str = server->connrec->username;
server->connrec->realname = g_strdup(str);
}
server->tag = server_create_tag(server->connrec);
server->connect_tag = -1;
}
| null | 0 | void server_connect_init(SERVER_REC *server)
{
const char *str;
g_return_if_fail(server != NULL);
MODULE_DATA_INIT(server);
server->type = module_get_uniq_id("SERVER", 0);
server_ref(server);
server->nick = g_strdup(server->connrec->nick);
if (server->connrec->username == NULL || *server->connrec->username == '\0') {
g_free_not_null(server->connrec->username);
str = g_get_user_name();
if (*str == '\0') str = "unknown";
server->connrec->username = g_strdup(str);
}
if (server->connrec->realname == NULL || *server->connrec->realname == '\0') {
g_free_not_null(server->connrec->realname);
str = g_get_real_name();
if (*str == '\0') str = server->connrec->username;
server->connrec->realname = g_strdup(str);
}
server->tag = server_create_tag(server->connrec);
server->connect_tag = -1;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,588 | void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
IPADDR *ip4, IPADDR *ip6)
{
if (ip4 == NULL || ip4->family == 0)
g_free_and_null(conn->own_ip4);
if (ip6 == NULL || ip6->family == 0)
g_free_and_null(conn->own_ip6);
if (ip4 != NULL && ip4->family != 0) {
/* IPv4 address was found */
if (conn->own_ip4 == NULL)
conn->own_ip4 = g_new0(IPADDR, 1);
memcpy(conn->own_ip4, ip4, sizeof(IPADDR));
}
if (ip6 != NULL && ip6->family != 0) {
/* IPv6 address was found */
if (conn->own_ip6 == NULL)
conn->own_ip6 = g_new0(IPADDR, 1);
memcpy(conn->own_ip6, ip6, sizeof(IPADDR));
}
}
| null | 0 | void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
IPADDR *ip4, IPADDR *ip6)
{
if (ip4 == NULL || ip4->family == 0)
g_free_and_null(conn->own_ip4);
if (ip6 == NULL || ip6->family == 0)
g_free_and_null(conn->own_ip6);
if (ip4 != NULL && ip4->family != 0) {
/* IPv4 address was found */
if (conn->own_ip4 == NULL)
conn->own_ip4 = g_new0(IPADDR, 1);
memcpy(conn->own_ip4, ip4, sizeof(IPADDR));
}
if (ip6 != NULL && ip6->family != 0) {
/* IPv6 address was found */
if (conn->own_ip6 == NULL)
conn->own_ip6 = g_new0(IPADDR, 1);
memcpy(conn->own_ip6, ip6, sizeof(IPADDR));
}
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,589 | void server_connect_unref(SERVER_CONNECT_REC *conn)
{
g_return_if_fail(IS_SERVER_CONNECT(conn));
if (--conn->refcount > 0)
return;
if (conn->refcount < 0) {
g_warning("Connection '%s' refcount = %d",
conn->tag, conn->refcount);
}
CHAT_PROTOCOL(conn)->destroy_server_connect(conn);
if (conn->connect_handle != NULL)
net_disconnect(conn->connect_handle);
g_free_not_null(conn->proxy);
g_free_not_null(conn->proxy_string);
g_free_not_null(conn->proxy_string_after);
g_free_not_null(conn->proxy_password);
g_free_not_null(conn->tag);
g_free_not_null(conn->address);
g_free_not_null(conn->chatnet);
g_free_not_null(conn->own_ip4);
g_free_not_null(conn->own_ip6);
g_free_not_null(conn->password);
g_free_not_null(conn->nick);
g_free_not_null(conn->username);
g_free_not_null(conn->realname);
g_free_not_null(conn->ssl_cert);
g_free_not_null(conn->ssl_pkey);
g_free_not_null(conn->ssl_cafile);
g_free_not_null(conn->ssl_capath);
g_free_not_null(conn->channels);
g_free_not_null(conn->away_reason);
conn->type = 0;
g_free(conn);
}
| null | 0 | void server_connect_unref(SERVER_CONNECT_REC *conn)
{
g_return_if_fail(IS_SERVER_CONNECT(conn));
if (--conn->refcount > 0)
return;
if (conn->refcount < 0) {
g_warning("Connection '%s' refcount = %d",
conn->tag, conn->refcount);
}
CHAT_PROTOCOL(conn)->destroy_server_connect(conn);
if (conn->connect_handle != NULL)
net_disconnect(conn->connect_handle);
g_free_not_null(conn->proxy);
g_free_not_null(conn->proxy_string);
g_free_not_null(conn->proxy_string_after);
g_free_not_null(conn->proxy_password);
g_free_not_null(conn->tag);
g_free_not_null(conn->address);
g_free_not_null(conn->chatnet);
g_free_not_null(conn->own_ip4);
g_free_not_null(conn->own_ip6);
g_free_not_null(conn->password);
g_free_not_null(conn->nick);
g_free_not_null(conn->username);
g_free_not_null(conn->realname);
g_free_not_null(conn->ssl_cert);
g_free_not_null(conn->ssl_pkey);
g_free_not_null(conn->ssl_cafile);
g_free_not_null(conn->ssl_capath);
g_free_not_null(conn->channels);
g_free_not_null(conn->away_reason);
conn->type = 0;
g_free(conn);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,590 | static char *server_create_address_tag(const char *address)
{
const char *start, *end;
g_return_val_if_fail(address != NULL, NULL);
/* try to generate a reasonable server tag */
if (strchr(address, '.') == NULL) {
start = end = NULL;
} else if (g_ascii_strncasecmp(address, "irc", 3) == 0 ||
g_ascii_strncasecmp(address, "chat", 4) == 0) {
/* irc-2.cs.hut.fi -> hut, chat.bt.net -> bt */
end = strrchr(address, '.');
start = end-1;
while (start > address && *start != '.') start--;
} else {
/* efnet.cs.hut.fi -> efnet */
end = strchr(address, '.');
start = end;
}
if (start == end) start = address; else start++;
if (end == NULL) end = address + strlen(address);
return g_strndup(start, (int) (end-start));
}
| null | 0 | static char *server_create_address_tag(const char *address)
{
const char *start, *end;
g_return_val_if_fail(address != NULL, NULL);
/* try to generate a reasonable server tag */
if (strchr(address, '.') == NULL) {
start = end = NULL;
} else if (g_ascii_strncasecmp(address, "irc", 3) == 0 ||
g_ascii_strncasecmp(address, "chat", 4) == 0) {
/* irc-2.cs.hut.fi -> hut, chat.bt.net -> bt */
end = strrchr(address, '.');
start = end-1;
while (start > address && *start != '.') start--;
} else {
/* efnet.cs.hut.fi -> efnet */
end = strchr(address, '.');
start = end;
}
if (start == end) start = address; else start++;
if (end == NULL) end = address + strlen(address);
return g_strndup(start, (int) (end-start));
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,591 | static char *server_create_tag(SERVER_CONNECT_REC *conn)
{
GString *str;
char *tag;
int num;
g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL);
tag = conn->chatnet != NULL && *conn->chatnet != '\0' ?
g_strdup(conn->chatnet) :
server_create_address_tag(conn->address);
if (conn->tag != NULL && server_find_tag(conn->tag) == NULL &&
server_find_lookup_tag(conn->tag) == NULL &&
strncmp(conn->tag, tag, strlen(tag)) == 0) {
/* use the existing tag if it begins with the same ID -
this is useful when you have several connections to
same server and you want to keep the same tags with
the servers (or it would cause problems when rejoining
/LAYOUT SAVEd channels). */
g_free(tag);
return g_strdup(conn->tag);
}
/* then just append numbers after tag until unused is found.. */
str = g_string_new(tag);
num = 2;
while (server_find_tag(str->str) != NULL ||
server_find_lookup_tag(str->str) != NULL) {
g_string_printf(str, "%s%d", tag, num);
num++;
}
g_free(tag);
tag = str->str;
g_string_free(str, FALSE);
return tag;
}
| null | 0 | static char *server_create_tag(SERVER_CONNECT_REC *conn)
{
GString *str;
char *tag;
int num;
g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL);
tag = conn->chatnet != NULL && *conn->chatnet != '\0' ?
g_strdup(conn->chatnet) :
server_create_address_tag(conn->address);
if (conn->tag != NULL && server_find_tag(conn->tag) == NULL &&
server_find_lookup_tag(conn->tag) == NULL &&
strncmp(conn->tag, tag, strlen(tag)) == 0) {
/* use the existing tag if it begins with the same ID -
this is useful when you have several connections to
same server and you want to keep the same tags with
the servers (or it would cause problems when rejoining
/LAYOUT SAVEd channels). */
g_free(tag);
return g_strdup(conn->tag);
}
/* then just append numbers after tag until unused is found.. */
str = g_string_new(tag);
num = 2;
while (server_find_tag(str->str) != NULL ||
server_find_lookup_tag(str->str) != NULL) {
g_string_printf(str, "%s%d", tag, num);
num++;
}
g_free(tag);
tag = str->str;
g_string_free(str, FALSE);
return tag;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,592 | void server_disconnect(SERVER_REC *server)
{
int chans;
g_return_if_fail(IS_SERVER(server));
if (server->disconnected)
return;
if (server->connect_tag != -1) {
/* still connecting to server.. */
if (server->connect_pid != -1)
net_disconnect_nonblock(server->connect_pid);
server_connect_failed(server, NULL);
return;
}
servers = g_slist_remove(servers, server);
server->disconnected = TRUE;
signal_emit("server disconnected", 1, server);
/* close all channels */
chans = server_remove_channels(server);
if (server->handle != NULL) {
if (!chans || server->connection_lost)
net_sendbuffer_destroy(server->handle, TRUE);
else {
/* we were on some channels, try to let the server
disconnect so that our quit message is guaranteed
to get displayed */
net_disconnect_later(net_sendbuffer_handle(server->handle));
net_sendbuffer_destroy(server->handle, FALSE);
}
server->handle = NULL;
}
if (server->readtag > 0) {
g_source_remove(server->readtag);
server->readtag = -1;
}
server_unref(server);
}
| null | 0 | void server_disconnect(SERVER_REC *server)
{
int chans;
g_return_if_fail(IS_SERVER(server));
if (server->disconnected)
return;
if (server->connect_tag != -1) {
/* still connecting to server.. */
if (server->connect_pid != -1)
net_disconnect_nonblock(server->connect_pid);
server_connect_failed(server, NULL);
return;
}
servers = g_slist_remove(servers, server);
server->disconnected = TRUE;
signal_emit("server disconnected", 1, server);
/* close all channels */
chans = server_remove_channels(server);
if (server->handle != NULL) {
if (!chans || server->connection_lost)
net_sendbuffer_destroy(server->handle, TRUE);
else {
/* we were on some channels, try to let the server
disconnect so that our quit message is guaranteed
to get displayed */
net_disconnect_later(net_sendbuffer_handle(server->handle));
net_sendbuffer_destroy(server->handle, FALSE);
}
server->handle = NULL;
}
if (server->readtag > 0) {
g_source_remove(server->readtag);
server->readtag = -1;
}
server_unref(server);
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,593 | SERVER_REC *server_find_chatnet(const char *chatnet)
{
GSList *tmp;
g_return_val_if_fail(chatnet != NULL, NULL);
if (*chatnet == '\0') return NULL;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (server->connrec->chatnet != NULL &&
g_strcasecmp(server->connrec->chatnet, chatnet) == 0)
return server;
}
return NULL;
}
| null | 0 | SERVER_REC *server_find_chatnet(const char *chatnet)
{
GSList *tmp;
g_return_val_if_fail(chatnet != NULL, NULL);
if (*chatnet == '\0') return NULL;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (server->connrec->chatnet != NULL &&
g_strcasecmp(server->connrec->chatnet, chatnet) == 0)
return server;
}
return NULL;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,594 | SERVER_REC *server_find_lookup_tag(const char *tag)
{
GSList *tmp;
g_return_val_if_fail(tag != NULL, NULL);
if (*tag == '\0') return NULL;
for (tmp = lookup_servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (g_strcasecmp(server->tag, tag) == 0)
return server;
}
return NULL;
}
| null | 0 | SERVER_REC *server_find_lookup_tag(const char *tag)
{
GSList *tmp;
g_return_val_if_fail(tag != NULL, NULL);
if (*tag == '\0') return NULL;
for (tmp = lookup_servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (g_strcasecmp(server->tag, tag) == 0)
return server;
}
return NULL;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,595 | SERVER_REC *server_find_tag(const char *tag)
{
GSList *tmp;
g_return_val_if_fail(tag != NULL, NULL);
if (*tag == '\0') return NULL;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (g_strcasecmp(server->tag, tag) == 0)
return server;
}
return NULL;
}
| null | 0 | SERVER_REC *server_find_tag(const char *tag)
{
GSList *tmp;
g_return_val_if_fail(tag != NULL, NULL);
if (*tag == '\0') return NULL;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
if (g_strcasecmp(server->tag, tag) == 0)
return server;
}
return NULL;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,596 | void server_ref(SERVER_REC *server)
{
g_return_if_fail(IS_SERVER(server));
server->refcount++;
}
| null | 0 | void server_ref(SERVER_REC *server)
{
g_return_if_fail(IS_SERVER(server));
server->refcount++;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,597 | int server_start_connect(SERVER_REC *server)
{
const char *connect_address;
int fd[2];
g_return_val_if_fail(server != NULL, FALSE);
if (!server->connrec->unix_socket && server->connrec->port <= 0)
return FALSE;
server->rawlog = rawlog_create();
if (server->connrec->connect_handle != NULL) {
/* already connected */
GIOChannel *handle = server->connrec->connect_handle;
server->connrec->connect_handle = NULL;
server->handle = net_sendbuffer_create(handle, 0);
server_connect_finished(server);
} else if (server->connrec->unix_socket) {
/* connect with unix socket */
server_real_connect(server, NULL, server->connrec->address);
} else {
/* resolve host name */
if (pipe(fd) != 0) {
g_warning("server_connect(): pipe() failed.");
g_free(server->tag);
g_free(server->nick);
return FALSE;
}
server->connect_pipe[0] = g_io_channel_unix_new(fd[0]);
server->connect_pipe[1] = g_io_channel_unix_new(fd[1]);
connect_address = server->connrec->proxy != NULL ?
server->connrec->proxy : server->connrec->address;
server->connect_pid =
net_gethostbyname_nonblock(connect_address,
server->connect_pipe[1],
settings_get_bool("resolve_reverse_lookup"));
server->connect_tag =
g_input_add(server->connect_pipe[0], G_INPUT_READ,
(GInputFunction)
server_connect_callback_readpipe,
server);
lookup_servers = g_slist_append(lookup_servers, server);
signal_emit("server looking", 1, server);
}
return TRUE;
}
| null | 0 | int server_start_connect(SERVER_REC *server)
{
const char *connect_address;
int fd[2];
g_return_val_if_fail(server != NULL, FALSE);
if (!server->connrec->unix_socket && server->connrec->port <= 0)
return FALSE;
server->rawlog = rawlog_create();
if (server->connrec->connect_handle != NULL) {
/* already connected */
GIOChannel *handle = server->connrec->connect_handle;
server->connrec->connect_handle = NULL;
server->handle = net_sendbuffer_create(handle, 0);
server_connect_finished(server);
} else if (server->connrec->unix_socket) {
/* connect with unix socket */
server_real_connect(server, NULL, server->connrec->address);
} else {
/* resolve host name */
if (pipe(fd) != 0) {
g_warning("server_connect(): pipe() failed.");
g_free(server->tag);
g_free(server->nick);
return FALSE;
}
server->connect_pipe[0] = g_io_channel_unix_new(fd[0]);
server->connect_pipe[1] = g_io_channel_unix_new(fd[1]);
connect_address = server->connrec->proxy != NULL ?
server->connrec->proxy : server->connrec->address;
server->connect_pid =
net_gethostbyname_nonblock(connect_address,
server->connect_pipe[1],
settings_get_bool("resolve_reverse_lookup"));
server->connect_tag =
g_input_add(server->connect_pipe[0], G_INPUT_READ,
(GInputFunction)
server_connect_callback_readpipe,
server);
lookup_servers = g_slist_append(lookup_servers, server);
signal_emit("server looking", 1, server);
}
return TRUE;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,598 | int server_unref(SERVER_REC *server)
{
g_return_val_if_fail(IS_SERVER(server), FALSE);
if (--server->refcount > 0)
return TRUE;
if (g_slist_find(servers, server) != NULL) {
g_warning("Non-referenced server wasn't disconnected");
server_disconnect(server);
return TRUE;
}
MODULE_DATA_DEINIT(server);
server_connect_unref(server->connrec);
if (server->rawlog != NULL) rawlog_destroy(server->rawlog);
g_free(server->version);
g_free(server->away_reason);
g_free(server->nick);
g_free(server->tag);
server->type = 0;
g_free(server);
return FALSE;
}
| null | 0 | int server_unref(SERVER_REC *server)
{
g_return_val_if_fail(IS_SERVER(server), FALSE);
if (--server->refcount > 0)
return TRUE;
if (g_slist_find(servers, server) != NULL) {
g_warning("Non-referenced server wasn't disconnected");
server_disconnect(server);
return TRUE;
}
MODULE_DATA_DEINIT(server);
server_connect_unref(server->connrec);
if (server->rawlog != NULL) rawlog_destroy(server->rawlog);
g_free(server->version);
g_free(server->away_reason);
g_free(server->nick);
g_free(server->tag);
server->type = 0;
g_free(server);
return FALSE;
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
14,599 | void servers_deinit(void)
{
signal_remove("chat protocol deinit", (SIGNAL_FUNC) sig_chat_protocol_deinit);
servers_setup_deinit();
servers_reconnect_deinit();
module_uniq_destroy("SERVER");
module_uniq_destroy("SERVER CONNECT");
}
| null | 0 | void servers_deinit(void)
{
signal_remove("chat protocol deinit", (SIGNAL_FUNC) sig_chat_protocol_deinit);
servers_setup_deinit();
servers_reconnect_deinit();
module_uniq_destroy("SERVER");
module_uniq_destroy("SERVER CONNECT");
}
| @@ -224,7 +224,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port;
handle = server->connrec->use_ssl ?
- net_connect_ip_ssl(ip, port, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
+ net_connect_ip_ssl(ip, port, server->connrec->address, own_ip, server->connrec->ssl_cert, server->connrec->ssl_pkey,
server->connrec->ssl_cafile, server->connrec->ssl_capath, server->connrec->ssl_verify) :
net_connect_ip(ip, port, own_ip);
} else { | CWE-20 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.