idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
11,700
get_kinfo_proc (pid_t pid, struct kinfo_proc *p) { int mib[4]; size_t len; len = 4; sysctlnametomib ("kern.proc.pid", mib, &len); len = sizeof (struct kinfo_proc); mib[3] = pid; if (sysctl (mib, 4, p, &len, NULL, 0) == -1) return FALSE; return TRUE; }
+Info
0
get_kinfo_proc (pid_t pid, struct kinfo_proc *p) { int mib[4]; size_t len; len = 4; sysctlnametomib ("kern.proc.pid", mib, &len); len = sizeof (struct kinfo_proc); mib[3] = pid; if (sysctl (mib, 4, p, &len, NULL, 0) == -1) return FALSE; return TRUE; }
@@ -56,6 +56,14 @@ * To uniquely identify processes, both the process id and the start * time of the process (a monotonic increasing value representing the * time since the kernel was started) is used. + * + * NOTE: This object stores, and provides access to, the real UID of the + * process. That value can change over time (with set*uid*(2) and exec*(2)). + * Checks whether an operation is allowed need to take care to use the UID + * value as of the time when the operation was made (or, following the open() + * privilege check model, when the connection making the operation possible + * was initiated). That is usually done by initializing this with + * polkit_unix_process_new_for_owner() with trusted data. */ /** @@ -90,9 +98,6 @@ static void subject_iface_init (PolkitSubjectIface *subject_iface); static guint64 get_start_time_for_pid (gint pid, GError **error); -static gint _polkit_unix_process_get_owner (PolkitUnixProcess *process, - GError **error); - #if defined(HAVE_FREEBSD) || defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) static gboolean get_kinfo_proc (gint pid, #if defined(HAVE_NETBSD) @@ -182,7 +187,7 @@ polkit_unix_process_constructed (GObject *object) { GError *error; error = NULL; - process->uid = _polkit_unix_process_get_owner (process, &error); + process->uid = polkit_unix_process_get_racy_uid__ (process, &error); if (error != NULL) { process->uid = -1; @@ -271,6 +276,12 @@ polkit_unix_process_class_init (PolkitUnixProcessClass *klass) * Gets the user id for @process. Note that this is the real user-id, * not the effective user-id. * + * NOTE: The UID may change over time, so the returned value may not match the + * current state of the underlying process; or the UID may have been set by + * polkit_unix_process_new_for_owner() or polkit_unix_process_set_uid(), + * in which case it may not correspond to the actual UID of the referenced + * process at all (at any point in time). + * * Returns: The user id for @process or -1 if unknown. */ gint @@ -708,13 +719,20 @@ out: return start_time; } -static gint -_polkit_unix_process_get_owner (PolkitUnixProcess *process, - GError **error) +/* + * Private: Return the "current" UID. Note that this is inherently racy, + * and the value may already be obsolete by the time this function returns; + * this function only guarantees that the UID was valid at some point during + * its execution. + */ +gint +polkit_unix_process_get_racy_uid__ (PolkitUnixProcess *process, + GError **error) { gint result; gchar *contents; gchar **lines; + guint64 start_time; #if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) struct kinfo_proc p; #elif defined(HAVE_NETBSD) @@ -722,6 +740,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, #else gchar filename[64]; guint n; + GError *local_error; #endif g_return_val_if_fail (POLKIT_IS_UNIX_PROCESS (process), 0); @@ -745,8 +764,10 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, #if defined(HAVE_FREEBSD) result = p.ki_uid; + start_time = (guint64) p.ki_start.tv_sec; #else result = p.p_uid; + start_time = (guint64) p.p_ustart_sec; #endif #else @@ -781,17 +802,37 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, else { result = real_uid; - goto out; + goto found; } } - g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Didn't find any line starting with `Uid:' in file %s", filename); + goto out; + +found: + /* The UID and start time are, sadly, not available in a single file. So, + * read the UID first, and then the start time; if the start time is the same + * before and after reading the UID, it couldn't have changed. + */ + local_error = NULL; + start_time = get_start_time_for_pid (process->pid, &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } #endif + if (process->start_time != start_time) + { + g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, + "process with PID %d has been replaced", process->pid); + goto out; + } + out: g_strfreev (lines); g_free (contents); @@ -810,5 +851,5 @@ gint polkit_unix_process_get_owner (PolkitUnixProcess *process, GError **error) { - return _polkit_unix_process_get_owner (process, error); + return polkit_unix_process_get_racy_uid__ (process, error); }
CWE-200
null
null
11,701
get_start_time_for_pid (pid_t pid, GError **error) { guint64 start_time; #if !defined(HAVE_FREEBSD) && !defined(HAVE_NETBSD) && !defined(HAVE_OPENBSD) gchar *filename; gchar *contents; size_t length; gchar **tokens; guint num_tokens; gchar *p; gchar *endp; start_time = 0; contents = NULL; filename = g_strdup_printf ("/proc/%d/stat", pid); if (!g_file_get_contents (filename, &contents, &length, error)) goto out; /* start time is the token at index 19 after the '(process name)' entry - since only this * field can contain the ')' character, search backwards for this to avoid malicious * processes trying to fool us */ p = strrchr (contents, ')'); if (p == NULL) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } p += 2; /* skip ') ' */ if (p - contents >= (int) length) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } tokens = g_strsplit (p, " ", 0); num_tokens = g_strv_length (tokens); if (num_tokens < 20) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } start_time = strtoull (tokens[19], &endp, 10); if (endp == tokens[19]) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } g_strfreev (tokens); out: g_free (filename); g_free (contents); #else #ifdef HAVE_NETBSD struct kinfo_proc2 p; #else struct kinfo_proc p; #endif start_time = 0; if (! get_kinfo_proc (pid, &p)) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error obtaining start time for %d (%s)", (gint) pid, g_strerror (errno)); goto out; } #ifdef HAVE_FREEBSD start_time = (guint64) p.ki_start.tv_sec; #else start_time = (guint64) p.p_ustart_sec; #endif out: #endif return start_time; }
+Info
0
get_start_time_for_pid (pid_t pid, GError **error) { guint64 start_time; #if !defined(HAVE_FREEBSD) && !defined(HAVE_NETBSD) && !defined(HAVE_OPENBSD) gchar *filename; gchar *contents; size_t length; gchar **tokens; guint num_tokens; gchar *p; gchar *endp; start_time = 0; contents = NULL; filename = g_strdup_printf ("/proc/%d/stat", pid); if (!g_file_get_contents (filename, &contents, &length, error)) goto out; /* start time is the token at index 19 after the '(process name)' entry - since only this * field can contain the ')' character, search backwards for this to avoid malicious * processes trying to fool us */ p = strrchr (contents, ')'); if (p == NULL) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } p += 2; /* skip ') ' */ if (p - contents >= (int) length) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } tokens = g_strsplit (p, " ", 0); num_tokens = g_strv_length (tokens); if (num_tokens < 20) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } start_time = strtoull (tokens[19], &endp, 10); if (endp == tokens[19]) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error parsing file %s", filename); goto out; } g_strfreev (tokens); out: g_free (filename); g_free (contents); #else #ifdef HAVE_NETBSD struct kinfo_proc2 p; #else struct kinfo_proc p; #endif start_time = 0; if (! get_kinfo_proc (pid, &p)) { g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Error obtaining start time for %d (%s)", (gint) pid, g_strerror (errno)); goto out; } #ifdef HAVE_FREEBSD start_time = (guint64) p.ki_start.tv_sec; #else start_time = (guint64) p.p_ustart_sec; #endif out: #endif return start_time; }
@@ -56,6 +56,14 @@ * To uniquely identify processes, both the process id and the start * time of the process (a monotonic increasing value representing the * time since the kernel was started) is used. + * + * NOTE: This object stores, and provides access to, the real UID of the + * process. That value can change over time (with set*uid*(2) and exec*(2)). + * Checks whether an operation is allowed need to take care to use the UID + * value as of the time when the operation was made (or, following the open() + * privilege check model, when the connection making the operation possible + * was initiated). That is usually done by initializing this with + * polkit_unix_process_new_for_owner() with trusted data. */ /** @@ -90,9 +98,6 @@ static void subject_iface_init (PolkitSubjectIface *subject_iface); static guint64 get_start_time_for_pid (gint pid, GError **error); -static gint _polkit_unix_process_get_owner (PolkitUnixProcess *process, - GError **error); - #if defined(HAVE_FREEBSD) || defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) static gboolean get_kinfo_proc (gint pid, #if defined(HAVE_NETBSD) @@ -182,7 +187,7 @@ polkit_unix_process_constructed (GObject *object) { GError *error; error = NULL; - process->uid = _polkit_unix_process_get_owner (process, &error); + process->uid = polkit_unix_process_get_racy_uid__ (process, &error); if (error != NULL) { process->uid = -1; @@ -271,6 +276,12 @@ polkit_unix_process_class_init (PolkitUnixProcessClass *klass) * Gets the user id for @process. Note that this is the real user-id, * not the effective user-id. * + * NOTE: The UID may change over time, so the returned value may not match the + * current state of the underlying process; or the UID may have been set by + * polkit_unix_process_new_for_owner() or polkit_unix_process_set_uid(), + * in which case it may not correspond to the actual UID of the referenced + * process at all (at any point in time). + * * Returns: The user id for @process or -1 if unknown. */ gint @@ -708,13 +719,20 @@ out: return start_time; } -static gint -_polkit_unix_process_get_owner (PolkitUnixProcess *process, - GError **error) +/* + * Private: Return the "current" UID. Note that this is inherently racy, + * and the value may already be obsolete by the time this function returns; + * this function only guarantees that the UID was valid at some point during + * its execution. + */ +gint +polkit_unix_process_get_racy_uid__ (PolkitUnixProcess *process, + GError **error) { gint result; gchar *contents; gchar **lines; + guint64 start_time; #if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) struct kinfo_proc p; #elif defined(HAVE_NETBSD) @@ -722,6 +740,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, #else gchar filename[64]; guint n; + GError *local_error; #endif g_return_val_if_fail (POLKIT_IS_UNIX_PROCESS (process), 0); @@ -745,8 +764,10 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, #if defined(HAVE_FREEBSD) result = p.ki_uid; + start_time = (guint64) p.ki_start.tv_sec; #else result = p.p_uid; + start_time = (guint64) p.p_ustart_sec; #endif #else @@ -781,17 +802,37 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, else { result = real_uid; - goto out; + goto found; } } - g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Didn't find any line starting with `Uid:' in file %s", filename); + goto out; + +found: + /* The UID and start time are, sadly, not available in a single file. So, + * read the UID first, and then the start time; if the start time is the same + * before and after reading the UID, it couldn't have changed. + */ + local_error = NULL; + start_time = get_start_time_for_pid (process->pid, &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } #endif + if (process->start_time != start_time) + { + g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, + "process with PID %d has been replaced", process->pid); + goto out; + } + out: g_strfreev (lines); g_free (contents); @@ -810,5 +851,5 @@ gint polkit_unix_process_get_owner (PolkitUnixProcess *process, GError **error) { - return _polkit_unix_process_get_owner (process, error); + return polkit_unix_process_get_racy_uid__ (process, error); }
CWE-200
null
null
11,702
_polkit_subject_get_cmdline (PolkitSubject *subject) { PolkitSubject *process; gchar *ret; gint pid; gchar *filename; gchar *contents; gsize contents_len; GError *error; guint n; g_return_val_if_fail (subject != NULL, NULL); error = NULL; ret = NULL; process = NULL; filename = NULL; contents = NULL; if (POLKIT_IS_UNIX_PROCESS (subject)) { process = g_object_ref (subject); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, &error); if (process == NULL) { g_printerr ("Error getting process for system bus name `%s': %s\n", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); goto out; } } else { g_warning ("Unknown subject type passed to _polkit_subject_get_cmdline()"); goto out; } pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (process)); filename = g_strdup_printf ("/proc/%d/cmdline", pid); if (!g_file_get_contents (filename, &contents, &contents_len, &error)) { g_printerr ("Error opening `%s': %s\n", filename, error->message); g_error_free (error); goto out; } if (contents == NULL || contents_len == 0) { goto out; } else { /* The kernel uses '\0' to separate arguments - replace those with a space. */ for (n = 0; n < contents_len - 1; n++) { if (contents[n] == '\0') contents[n] = ' '; } ret = g_strdup (contents); g_strstrip (ret); } out: g_free (filename); g_free (contents); if (process != NULL) g_object_unref (process); return ret; }
+Info
0
_polkit_subject_get_cmdline (PolkitSubject *subject) { PolkitSubject *process; gchar *ret; gint pid; gchar *filename; gchar *contents; gsize contents_len; GError *error; guint n; g_return_val_if_fail (subject != NULL, NULL); error = NULL; ret = NULL; process = NULL; filename = NULL; contents = NULL; if (POLKIT_IS_UNIX_PROCESS (subject)) { process = g_object_ref (subject); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, &error); if (process == NULL) { g_printerr ("Error getting process for system bus name `%s': %s\n", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); goto out; } } else { g_warning ("Unknown subject type passed to _polkit_subject_get_cmdline()"); goto out; } pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (process)); filename = g_strdup_printf ("/proc/%d/cmdline", pid); if (!g_file_get_contents (filename, &contents, &contents_len, &error)) { g_printerr ("Error opening `%s': %s\n", filename, error->message); g_error_free (error); goto out; } if (contents == NULL || contents_len == 0) { goto out; } else { /* The kernel uses '\0' to separate arguments - replace those with a space. */ for (n = 0; n < contents_len - 1; n++) { if (contents[n] == '\0') contents[n] = ' '; } ret = g_strdup (contents); g_strstrip (ret); } out: g_free (filename); g_free (contents); if (process != NULL) g_object_unref (process); return ret; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,703
action_pool_changed (PolkitBackendActionPool *action_pool, PolkitBackendInteractiveAuthority *authority) { g_signal_emit_by_name (authority, "changed"); }
+Info
0
action_pool_changed (PolkitBackendActionPool *action_pool, PolkitBackendInteractiveAuthority *authority) { g_signal_emit_by_name (authority, "changed"); }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,704
check_authorization_challenge_cb (AuthenticationAgent *agent, PolkitSubject *subject, PolkitIdentity *user_of_subject, PolkitSubject *caller, PolkitBackendInteractiveAuthority *authority, const gchar *action_id, PolkitDetails *details, PolkitImplicitAuthorization implicit_authorization, gboolean authentication_success, gboolean was_dismissed, PolkitIdentity *authenticated_identity, gpointer user_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); PolkitBackendInteractiveAuthorityPrivate *priv; PolkitAuthorizationResult *result; gchar *scope_str; gchar *subject_str; gchar *user_of_subject_str; gchar *authenticated_identity_str; gchar *subject_cmdline; gboolean is_temp; priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); result = NULL; scope_str = polkit_subject_to_string (agent->scope); subject_str = polkit_subject_to_string (subject); user_of_subject_str = polkit_identity_to_string (user_of_subject); authenticated_identity_str = NULL; if (authenticated_identity != NULL) authenticated_identity_str = polkit_identity_to_string (authenticated_identity); subject_cmdline = _polkit_subject_get_cmdline (subject); if (subject_cmdline == NULL) subject_cmdline = g_strdup ("<unknown>"); g_debug ("In check_authorization_challenge_cb\n" " subject %s\n" " action_id %s\n" " was_dismissed %d\n" " authentication_success %d\n", subject_str, action_id, was_dismissed, authentication_success); if (implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED || implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED) polkit_details_insert (details, "polkit.retains_authorization_after_challenge", "true"); is_temp = FALSE; if (authentication_success) { /* store temporary authorization depending on value of implicit_authorization */ if (implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED || implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED) { const gchar *id; is_temp = TRUE; id = temporary_authorization_store_add_authorization (priv->temporary_authorization_store, subject, authentication_agent_get_scope (agent), action_id); polkit_details_insert (details, "polkit.temporary_authorization_id", id); /* we've added a temporary authorization, let the user know */ g_signal_emit_by_name (authority, "changed"); } result = polkit_authorization_result_new (TRUE, FALSE, details); } else { /* TODO: maybe return set is_challenge? */ if (was_dismissed) polkit_details_insert (details, "polkit.dismissed", "true"); result = polkit_authorization_result_new (FALSE, FALSE, details); } /* Log the event */ if (authentication_success) { if (is_temp) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s successfully authenticated as %s to gain " "TEMPORARY authorization for action %s for %s [%s] (owned by %s)", scope_str, authenticated_identity_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } else { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s successfully authenticated as %s to gain " "ONE-SHOT authorization for action %s for %s [%s] (owned by %s)", scope_str, authenticated_identity_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } } else { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s FAILED to authenticate to gain " "authorization for action %s for %s [%s] (owned by %s)", scope_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } /* log_result (authority, action_id, subject, caller, result); */ g_simple_async_result_set_op_res_gpointer (simple, result, g_object_unref); g_simple_async_result_complete (simple); g_object_unref (simple); g_free (subject_cmdline); g_free (authenticated_identity_str); g_free (user_of_subject_str); g_free (subject_str); g_free (scope_str); }
+Info
0
check_authorization_challenge_cb (AuthenticationAgent *agent, PolkitSubject *subject, PolkitIdentity *user_of_subject, PolkitSubject *caller, PolkitBackendInteractiveAuthority *authority, const gchar *action_id, PolkitDetails *details, PolkitImplicitAuthorization implicit_authorization, gboolean authentication_success, gboolean was_dismissed, PolkitIdentity *authenticated_identity, gpointer user_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); PolkitBackendInteractiveAuthorityPrivate *priv; PolkitAuthorizationResult *result; gchar *scope_str; gchar *subject_str; gchar *user_of_subject_str; gchar *authenticated_identity_str; gchar *subject_cmdline; gboolean is_temp; priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); result = NULL; scope_str = polkit_subject_to_string (agent->scope); subject_str = polkit_subject_to_string (subject); user_of_subject_str = polkit_identity_to_string (user_of_subject); authenticated_identity_str = NULL; if (authenticated_identity != NULL) authenticated_identity_str = polkit_identity_to_string (authenticated_identity); subject_cmdline = _polkit_subject_get_cmdline (subject); if (subject_cmdline == NULL) subject_cmdline = g_strdup ("<unknown>"); g_debug ("In check_authorization_challenge_cb\n" " subject %s\n" " action_id %s\n" " was_dismissed %d\n" " authentication_success %d\n", subject_str, action_id, was_dismissed, authentication_success); if (implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED || implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED) polkit_details_insert (details, "polkit.retains_authorization_after_challenge", "true"); is_temp = FALSE; if (authentication_success) { /* store temporary authorization depending on value of implicit_authorization */ if (implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED || implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED) { const gchar *id; is_temp = TRUE; id = temporary_authorization_store_add_authorization (priv->temporary_authorization_store, subject, authentication_agent_get_scope (agent), action_id); polkit_details_insert (details, "polkit.temporary_authorization_id", id); /* we've added a temporary authorization, let the user know */ g_signal_emit_by_name (authority, "changed"); } result = polkit_authorization_result_new (TRUE, FALSE, details); } else { /* TODO: maybe return set is_challenge? */ if (was_dismissed) polkit_details_insert (details, "polkit.dismissed", "true"); result = polkit_authorization_result_new (FALSE, FALSE, details); } /* Log the event */ if (authentication_success) { if (is_temp) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s successfully authenticated as %s to gain " "TEMPORARY authorization for action %s for %s [%s] (owned by %s)", scope_str, authenticated_identity_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } else { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s successfully authenticated as %s to gain " "ONE-SHOT authorization for action %s for %s [%s] (owned by %s)", scope_str, authenticated_identity_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } } else { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Operator of %s FAILED to authenticate to gain " "authorization for action %s for %s [%s] (owned by %s)", scope_str, action_id, subject_str, subject_cmdline, user_of_subject_str); } /* log_result (authority, action_id, subject, caller, result); */ g_simple_async_result_set_op_res_gpointer (simple, result, g_object_unref); g_simple_async_result_complete (simple); g_object_unref (simple); g_free (subject_cmdline); g_free (authenticated_identity_str); g_free (user_of_subject_str); g_free (subject_str); g_free (scope_str); }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,705
identity_is_root_user (PolkitIdentity *user) { if (!POLKIT_IS_UNIX_USER (user)) return FALSE; return polkit_unix_user_get_uid (POLKIT_UNIX_USER (user)) == 0; }
+Info
0
identity_is_root_user (PolkitIdentity *user) { if (!POLKIT_IS_UNIX_USER (user)) return FALSE; return polkit_unix_user_get_uid (POLKIT_UNIX_USER (user)) == 0; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,706
may_identity_check_authorization (PolkitBackendInteractiveAuthority *interactive_authority, const gchar *action_id, PolkitIdentity *identity) { PolkitBackendInteractiveAuthorityPrivate *priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); gboolean ret = FALSE; PolkitActionDescription *action_desc = NULL; const gchar *owners = NULL; gchar **tokens = NULL; guint n; /* uid 0 may check anything */ if (identity_is_root_user (identity)) { ret = TRUE; goto out; } action_desc = polkit_backend_action_pool_get_action (priv->action_pool, action_id, NULL); if (action_desc == NULL) goto out; owners = polkit_action_description_get_annotation (action_desc, "org.freedesktop.policykit.owner"); if (owners == NULL) goto out; tokens = g_strsplit (owners, " ", 0); for (n = 0; tokens != NULL && tokens[n] != NULL; n++) { PolkitIdentity *owner_identity; GError *error = NULL; owner_identity = polkit_identity_from_string (tokens[n], &error); if (owner_identity == NULL) { g_warning ("Error parsing owner identity %d of action_id %s: %s (%s, %d)", n, action_id, error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); continue; } if (polkit_identity_equal (identity, owner_identity)) { ret = TRUE; g_object_unref (owner_identity); goto out; } g_object_unref (owner_identity); } out: g_clear_object (&action_desc); g_strfreev (tokens); return ret; }
+Info
0
may_identity_check_authorization (PolkitBackendInteractiveAuthority *interactive_authority, const gchar *action_id, PolkitIdentity *identity) { PolkitBackendInteractiveAuthorityPrivate *priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); gboolean ret = FALSE; PolkitActionDescription *action_desc = NULL; const gchar *owners = NULL; gchar **tokens = NULL; guint n; /* uid 0 may check anything */ if (identity_is_root_user (identity)) { ret = TRUE; goto out; } action_desc = polkit_backend_action_pool_get_action (priv->action_pool, action_id, NULL); if (action_desc == NULL) goto out; owners = polkit_action_description_get_annotation (action_desc, "org.freedesktop.policykit.owner"); if (owners == NULL) goto out; tokens = g_strsplit (owners, " ", 0); for (n = 0; tokens != NULL && tokens[n] != NULL; n++) { PolkitIdentity *owner_identity; GError *error = NULL; owner_identity = polkit_identity_from_string (tokens[n], &error); if (owner_identity == NULL) { g_warning ("Error parsing owner identity %d of action_id %s: %s (%s, %d)", n, action_id, error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); continue; } if (polkit_identity_equal (identity, owner_identity)) { ret = TRUE; g_object_unref (owner_identity); goto out; } g_object_unref (owner_identity); } out: g_clear_object (&action_desc); g_strfreev (tokens); return ret; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,707
on_name_owner_changed_signal (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { PolkitBackendInteractiveAuthority *authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (user_data); const gchar *name; const gchar *old_owner; const gchar *new_owner; g_variant_get (parameters, "(&s&s&s)", &name, &old_owner, &new_owner); polkit_backend_interactive_authority_system_bus_name_owner_changed (authority, name, old_owner, new_owner); }
+Info
0
on_name_owner_changed_signal (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { PolkitBackendInteractiveAuthority *authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (user_data); const gchar *name; const gchar *old_owner; const gchar *new_owner; g_variant_get (parameters, "(&s&s&s)", &name, &old_owner, &new_owner); polkit_backend_interactive_authority_system_bus_name_owner_changed (authority, name, old_owner, new_owner); }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,708
polkit_backend_interactive_authority_check_authorization_finish (PolkitBackendAuthority *authority, GAsyncResult *res, GError **error) { GSimpleAsyncResult *simple; PolkitAuthorizationResult *result; simple = G_SIMPLE_ASYNC_RESULT (res); g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_backend_interactive_authority_check_authorization); result = NULL; if (g_simple_async_result_propagate_error (simple, error)) goto out; result = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); out: return result; }
+Info
0
polkit_backend_interactive_authority_check_authorization_finish (PolkitBackendAuthority *authority, GAsyncResult *res, GError **error) { GSimpleAsyncResult *simple; PolkitAuthorizationResult *result; simple = G_SIMPLE_ASYNC_RESULT (res); g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_backend_interactive_authority_check_authorization); result = NULL; if (g_simple_async_result_propagate_error (simple, error)) goto out; result = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); out: return result; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,709
polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthorityClass *klass) { GObjectClass *gobject_class; PolkitBackendAuthorityClass *authority_class; gobject_class = G_OBJECT_CLASS (klass); authority_class = POLKIT_BACKEND_AUTHORITY_CLASS (klass); gobject_class->finalize = polkit_backend_interactive_authority_finalize; authority_class->get_name = polkit_backend_interactive_authority_get_name; authority_class->get_version = polkit_backend_interactive_authority_get_version; authority_class->get_features = polkit_backend_interactive_authority_get_features; authority_class->enumerate_actions = polkit_backend_interactive_authority_enumerate_actions; authority_class->check_authorization = polkit_backend_interactive_authority_check_authorization; authority_class->check_authorization_finish = polkit_backend_interactive_authority_check_authorization_finish; authority_class->register_authentication_agent = polkit_backend_interactive_authority_register_authentication_agent; authority_class->unregister_authentication_agent = polkit_backend_interactive_authority_unregister_authentication_agent; authority_class->authentication_agent_response = polkit_backend_interactive_authority_authentication_agent_response; authority_class->enumerate_temporary_authorizations = polkit_backend_interactive_authority_enumerate_temporary_authorizations; authority_class->revoke_temporary_authorizations = polkit_backend_interactive_authority_revoke_temporary_authorizations; authority_class->revoke_temporary_authorization_by_id = polkit_backend_interactive_authority_revoke_temporary_authorization_by_id; g_type_class_add_private (klass, sizeof (PolkitBackendInteractiveAuthorityPrivate)); }
+Info
0
polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthorityClass *klass) { GObjectClass *gobject_class; PolkitBackendAuthorityClass *authority_class; gobject_class = G_OBJECT_CLASS (klass); authority_class = POLKIT_BACKEND_AUTHORITY_CLASS (klass); gobject_class->finalize = polkit_backend_interactive_authority_finalize; authority_class->get_name = polkit_backend_interactive_authority_get_name; authority_class->get_version = polkit_backend_interactive_authority_get_version; authority_class->get_features = polkit_backend_interactive_authority_get_features; authority_class->enumerate_actions = polkit_backend_interactive_authority_enumerate_actions; authority_class->check_authorization = polkit_backend_interactive_authority_check_authorization; authority_class->check_authorization_finish = polkit_backend_interactive_authority_check_authorization_finish; authority_class->register_authentication_agent = polkit_backend_interactive_authority_register_authentication_agent; authority_class->unregister_authentication_agent = polkit_backend_interactive_authority_unregister_authentication_agent; authority_class->authentication_agent_response = polkit_backend_interactive_authority_authentication_agent_response; authority_class->enumerate_temporary_authorizations = polkit_backend_interactive_authority_enumerate_temporary_authorizations; authority_class->revoke_temporary_authorizations = polkit_backend_interactive_authority_revoke_temporary_authorizations; authority_class->revoke_temporary_authorization_by_id = polkit_backend_interactive_authority_revoke_temporary_authorization_by_id; g_type_class_add_private (klass, sizeof (PolkitBackendInteractiveAuthorityPrivate)); }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,710
polkit_backend_interactive_authority_finalize (GObject *object) { PolkitBackendInteractiveAuthority *interactive_authority; PolkitBackendInteractiveAuthorityPrivate *priv; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (object); priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); if (priv->name_owner_changed_signal_id > 0) g_dbus_connection_signal_unsubscribe (priv->system_bus_connection, priv->name_owner_changed_signal_id); if (priv->system_bus_connection != NULL) g_object_unref (priv->system_bus_connection); if (priv->action_pool != NULL) g_object_unref (priv->action_pool); if (priv->session_monitor != NULL) g_object_unref (priv->session_monitor); temporary_authorization_store_free (priv->temporary_authorization_store); g_hash_table_unref (priv->hash_scope_to_authentication_agent); G_OBJECT_CLASS (polkit_backend_interactive_authority_parent_class)->finalize (object); }
+Info
0
polkit_backend_interactive_authority_finalize (GObject *object) { PolkitBackendInteractiveAuthority *interactive_authority; PolkitBackendInteractiveAuthorityPrivate *priv; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (object); priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); if (priv->name_owner_changed_signal_id > 0) g_dbus_connection_signal_unsubscribe (priv->system_bus_connection, priv->name_owner_changed_signal_id); if (priv->system_bus_connection != NULL) g_object_unref (priv->system_bus_connection); if (priv->action_pool != NULL) g_object_unref (priv->action_pool); if (priv->session_monitor != NULL) g_object_unref (priv->session_monitor); temporary_authorization_store_free (priv->temporary_authorization_store); g_hash_table_unref (priv->hash_scope_to_authentication_agent); G_OBJECT_CLASS (polkit_backend_interactive_authority_parent_class)->finalize (object); }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,711
polkit_backend_interactive_authority_get_features (PolkitBackendAuthority *authority) { return POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION; }
+Info
0
polkit_backend_interactive_authority_get_features (PolkitBackendAuthority *authority) { return POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,712
polkit_backend_interactive_authority_get_name (PolkitBackendAuthority *authority) { return "interactive"; }
+Info
0
polkit_backend_interactive_authority_get_name (PolkitBackendAuthority *authority) { return "interactive"; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,713
polkit_backend_interactive_authority_get_version (PolkitBackendAuthority *authority) { return PACKAGE_VERSION; }
+Info
0
polkit_backend_interactive_authority_get_version (PolkitBackendAuthority *authority) { return PACKAGE_VERSION; }
@@ -575,7 +575,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, if (polkit_authorization_result_get_is_authorized (result)) log_result_str = "ALLOWING"; - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL, NULL); subject_str = polkit_subject_to_string (subject); @@ -847,6 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar *subject_str; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; gchar *user_of_caller_str; gchar *user_of_subject_str; PolkitAuthorizationResult *result; @@ -892,7 +893,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority action_id); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, &error); if (error != NULL) { @@ -907,7 +908,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority g_debug (" user of caller is %s", user_of_caller_str); user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, &user_of_subject_matches, &error); if (error != NULL) { @@ -937,7 +938,10 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * We only allow this if, and only if, * * - processes may check for another process owned by the *same* user but not - * if details are passed (otherwise you'd be able to spoof the dialog) + * if details are passed (otherwise you'd be able to spoof the dialog); + * the caller supplies the user_of_subject value, so we additionally + * require it to match at least at one point in time (via + * user_of_subject_matches). * * - processes running as uid 0 may check anything and pass any details * @@ -945,7 +949,9 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority * then any uid referenced by that annotation is also allowed to check * to check anything and pass any details */ - if (!polkit_identity_equal (user_of_caller, user_of_subject) || has_details) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject) + || has_details) { if (!may_identity_check_authorization (interactive_authority, action_id, user_of_caller)) { @@ -1110,9 +1116,10 @@ check_authorization_sync (PolkitBackendAuthority *authority, goto out; } - /* every subject has a user */ + /* every subject has a user; this is supplied by the client, so we rely + * on the caller to validate its acceptability. */ user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - subject, + subject, NULL, error); if (user_of_subject == NULL) goto out; @@ -2480,6 +2487,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *caller_cmdline; @@ -2532,7 +2540,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2541,7 +2549,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2550,7 +2558,8 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2643,6 +2652,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack PolkitSubject *session_for_caller; PolkitIdentity *user_of_caller; PolkitIdentity *user_of_subject; + gboolean user_of_subject_matches; AuthenticationAgent *agent; gboolean ret; gchar *scope_str; @@ -2691,7 +2701,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack goto out; } - user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL); + user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, caller, NULL, NULL); if (user_of_caller == NULL) { g_set_error (error, @@ -2700,7 +2710,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of caller"); goto out; } - user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, NULL); + user_of_subject = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, subject, &user_of_subject_matches, NULL); if (user_of_subject == NULL) { g_set_error (error, @@ -2709,7 +2719,8 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack "Cannot determine user of subject"); goto out; } - if (!polkit_identity_equal (user_of_caller, user_of_subject)) + if (!user_of_subject_matches + || !polkit_identity_equal (user_of_caller, user_of_subject)) { if (identity_is_root_user (user_of_caller)) { @@ -2819,7 +2830,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken identity_str); user_of_caller = polkit_backend_session_monitor_get_user_for_subject (priv->session_monitor, - caller, + caller, NULL, error); if (user_of_caller == NULL) goto out;
CWE-200
null
null
11,714
polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = polkit_backend_session_monitor_finalize; /** * PolkitBackendSessionMonitor::changed: * @monitor: A #PolkitBackendSessionMonitor * * Emitted when something changes. */ signals[CHANGED_SIGNAL] = g_signal_new ("changed", POLKIT_BACKEND_TYPE_SESSION_MONITOR, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (PolkitBackendSessionMonitorClass, changed), NULL, /* accumulator */ NULL, /* accumulator data */ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); }
+Info
0
polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = polkit_backend_session_monitor_finalize; /** * PolkitBackendSessionMonitor::changed: * @monitor: A #PolkitBackendSessionMonitor * * Emitted when something changes. */ signals[CHANGED_SIGNAL] = g_signal_new ("changed", POLKIT_BACKEND_TYPE_SESSION_MONITOR, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (PolkitBackendSessionMonitorClass, changed), NULL, /* accumulator */ NULL, /* accumulator data */ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,715
polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor) { /* TODO */ return NULL; }
+Info
0
polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor) { /* TODO */ return NULL; }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,716
polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) { GError *error; error = NULL; monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (monitor->system_bus == NULL) { g_printerr ("Error getting system bus: %s", error->message); g_error_free (error); } monitor->sd_source = sd_source_new (); g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL); g_source_attach (monitor->sd_source, NULL); }
+Info
0
polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) { GError *error; error = NULL; monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (monitor->system_bus == NULL) { g_printerr ("Error getting system bus: %s", error->message); g_error_free (error); } monitor->sd_source = sd_source_new (); g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL); g_source_attach (monitor->sd_source, NULL); }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,717
sd_source_check (GSource *source) { SdSource *sd_source = (SdSource *)source; return sd_source->pollfd.revents != 0; }
+Info
0
sd_source_check (GSource *source) { SdSource *sd_source = (SdSource *)source; return sd_source->pollfd.revents != 0; }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,718
sd_source_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) { SdSource *sd_source = (SdSource *)source; gboolean ret; g_warn_if_fail (callback != NULL); ret = (*callback) (user_data); sd_login_monitor_flush (sd_source->monitor); return ret; }
+Info
0
sd_source_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) { SdSource *sd_source = (SdSource *)source; gboolean ret; g_warn_if_fail (callback != NULL); ret = (*callback) (user_data); sd_login_monitor_flush (sd_source->monitor); return ret; }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,719
sd_source_finalize (GSource *source) { SdSource *sd_source = (SdSource*)source; sd_login_monitor_unref (sd_source->monitor); }
+Info
0
sd_source_finalize (GSource *source) { SdSource *sd_source = (SdSource*)source; sd_login_monitor_unref (sd_source->monitor); }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,720
sd_source_new (void) { GSource *source; SdSource *sd_source; int ret; source = g_source_new (&sd_source_funcs, sizeof (SdSource)); sd_source = (SdSource *)source; if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) { g_printerr ("Error getting login monitor: %d", ret); } else { sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor); sd_source->pollfd.events = G_IO_IN; g_source_add_poll (source, &sd_source->pollfd); } return source; }
+Info
0
sd_source_new (void) { GSource *source; SdSource *sd_source; int ret; source = g_source_new (&sd_source_funcs, sizeof (SdSource)); sd_source = (SdSource *)source; if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) { g_printerr ("Error getting login monitor: %d", ret); } else { sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor); sd_source->pollfd.events = G_IO_IN; g_source_add_poll (source, &sd_source->pollfd); } return source; }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,721
sessions_changed (gpointer user_data) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); return TRUE; }
+Info
0
sessions_changed (gpointer user_data) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); return TRUE; }
@@ -29,6 +29,7 @@ #include <stdlib.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" /* <internal> @@ -246,26 +247,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; - guint32 uid; + gboolean matches; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + GError *local_error; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -273,14 +288,24 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + uid_t uid; if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) { @@ -292,9 +317,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor } ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,722
ensure_database (PolkitBackendSessionMonitor *monitor, GError **error) { gboolean ret = FALSE; if (monitor->database != NULL) { struct stat statbuf; if (stat (CKDB_PATH, &statbuf) != 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Error statting file " CKDB_PATH " to check timestamp: %s", strerror (errno)); goto out; } if (statbuf.st_mtime == monitor->database_mtime) { ret = TRUE; goto out; } } ret = reload_database (monitor, error); out: return ret; }
+Info
0
ensure_database (PolkitBackendSessionMonitor *monitor, GError **error) { gboolean ret = FALSE; if (monitor->database != NULL) { struct stat statbuf; if (stat (CKDB_PATH, &statbuf) != 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Error statting file " CKDB_PATH " to check timestamp: %s", strerror (errno)); goto out; } if (statbuf.st_mtime == monitor->database_mtime) { ret = TRUE; goto out; } } ret = reload_database (monitor, error); out: return ret; }
@@ -27,6 +27,7 @@ #include <glib/gstdio.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" #define CKDB_PATH "/var/run/ConsoleKit/database" @@ -273,28 +274,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; + gboolean matches; GError *local_error; - gchar *group; - guint32 uid; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -302,14 +315,26 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + gint uid; + gchar *group; + if (!ensure_database (monitor, error)) { g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": "); @@ -328,9 +353,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor g_free (group); ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,723
on_file_monitor_changed (GFileMonitor *file_monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); /* throw away cache */ if (monitor->database != NULL) { g_key_file_free (monitor->database); monitor->database = NULL; } g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); }
+Info
0
on_file_monitor_changed (GFileMonitor *file_monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); /* throw away cache */ if (monitor->database != NULL) { g_key_file_free (monitor->database); monitor->database = NULL; } g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); }
@@ -27,6 +27,7 @@ #include <glib/gstdio.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" #define CKDB_PATH "/var/run/ConsoleKit/database" @@ -273,28 +274,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; + gboolean matches; GError *local_error; - gchar *group; - guint32 uid; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -302,14 +315,26 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + gint uid; + gchar *group; + if (!ensure_database (monitor, error)) { g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": "); @@ -328,9 +353,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor g_free (group); ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,724
polkit_backend_session_monitor_finalize (GObject *object) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object); if (monitor->system_bus != NULL) g_object_unref (monitor->system_bus); if (monitor->database_monitor != NULL) g_object_unref (monitor->database_monitor); if (monitor->database != NULL) g_key_file_free (monitor->database); if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL) G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object); }
+Info
0
polkit_backend_session_monitor_finalize (GObject *object) { PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object); if (monitor->system_bus != NULL) g_object_unref (monitor->system_bus); if (monitor->database_monitor != NULL) g_object_unref (monitor->database_monitor); if (monitor->database != NULL) g_key_file_free (monitor->database); if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL) G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object); }
@@ -27,6 +27,7 @@ #include <glib/gstdio.h> #include <polkit/polkit.h> +#include <polkit/polkitprivate.h> #include "polkitbackendsessionmonitor.h" #define CKDB_PATH "/var/run/ConsoleKit/database" @@ -273,28 +274,40 @@ polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monito * polkit_backend_session_monitor_get_user: * @monitor: A #PolkitBackendSessionMonitor. * @subject: A #PolkitSubject. + * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. * @error: Return location for error. * * Gets the user corresponding to @subject or %NULL if no user exists. * + * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may + * come from e.g. a D-Bus client), so it may not correspond to the actual UID + * of the referenced process (at any point in time). This is indicated by + * setting @result_matches to %FALSE; the caller may reject such subjects or + * require additional privileges. @result_matches == %TRUE only indicates that + * the UID matched the underlying process at ONE point in time, it may not match + * later. + * * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). */ PolkitIdentity * polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, PolkitSubject *subject, + gboolean *result_matches, GError **error) { PolkitIdentity *ret; + gboolean matches; GError *local_error; - gchar *group; - guint32 uid; ret = NULL; + matches = FALSE; if (POLKIT_IS_UNIX_PROCESS (subject)) { - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); - if ((gint) uid == -1) + gint subject_uid, current_uid; + + subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); + if (subject_uid == -1) { g_set_error (error, POLKIT_ERROR, @@ -302,14 +315,26 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor "Unix process subject does not have uid set"); goto out; } - ret = polkit_unix_user_new (uid); + local_error = NULL; + current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); + if (local_error != NULL) + { + g_propagate_error (error, local_error); + goto out; + } + ret = polkit_unix_user_new (subject_uid); + matches = (subject_uid == current_uid); } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); + matches = TRUE; } else if (POLKIT_IS_UNIX_SESSION (subject)) { + gint uid; + gchar *group; + if (!ensure_database (monitor, error)) { g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": "); @@ -328,9 +353,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor g_free (group); ret = polkit_unix_user_new (uid); + matches = TRUE; } out: + if (result_matches != NULL) + { + *result_matches = matches; + } return ret; }
CWE-200
null
null
11,725
PHP_FUNCTION(bin2hex) { zend_string *result; zend_string *data; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data) == FAILURE) { return; } result = php_bin2hex((unsigned char *)ZSTR_VAL(data), ZSTR_LEN(data)); if (!result) { RETURN_FALSE; } RETURN_STR(result); }
Exec Code
0
PHP_FUNCTION(bin2hex) { zend_string *result; zend_string *data; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data) == FAILURE) { return; } result = php_bin2hex((unsigned char *)ZSTR_VAL(data), ZSTR_LEN(data)); if (!result) { RETURN_FALSE; } RETURN_STR(result); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,726
PHP_FUNCTION(strspn) { php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRSPN); }
Exec Code
0
PHP_FUNCTION(strspn) { php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRSPN); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,727
PHP_FUNCTION(strcspn) { php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRCSPN); }
Exec Code
0
PHP_FUNCTION(strcspn) { php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRCSPN); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,728
PHP_FUNCTION(nl_langinfo) { zend_long item; char *value; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &item) == FAILURE) { return; } switch(item) { /* {{{ */ #ifdef ABDAY_1 case ABDAY_1: case ABDAY_2: case ABDAY_3: case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: #endif #ifdef DAY_1 case DAY_1: case DAY_2: case DAY_3: case DAY_4: case DAY_5: case DAY_6: case DAY_7: #endif #ifdef ABMON_1 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: #endif #ifdef MON_1 case MON_1: case MON_2: case MON_3: case MON_4: case MON_5: case MON_6: case MON_7: case MON_8: case MON_9: case MON_10: case MON_11: case MON_12: #endif #ifdef AM_STR case AM_STR: #endif #ifdef PM_STR case PM_STR: #endif #ifdef D_T_FMT case D_T_FMT: #endif #ifdef D_FMT case D_FMT: #endif #ifdef T_FMT case T_FMT: #endif #ifdef T_FMT_AMPM case T_FMT_AMPM: #endif #ifdef ERA case ERA: #endif #ifdef ERA_YEAR case ERA_YEAR: #endif #ifdef ERA_D_T_FMT case ERA_D_T_FMT: #endif #ifdef ERA_D_FMT case ERA_D_FMT: #endif #ifdef ERA_T_FMT case ERA_T_FMT: #endif #ifdef ALT_DIGITS case ALT_DIGITS: #endif #ifdef INT_CURR_SYMBOL case INT_CURR_SYMBOL: #endif #ifdef CURRENCY_SYMBOL case CURRENCY_SYMBOL: #endif #ifdef CRNCYSTR case CRNCYSTR: #endif #ifdef MON_DECIMAL_POINT case MON_DECIMAL_POINT: #endif #ifdef MON_THOUSANDS_SEP case MON_THOUSANDS_SEP: #endif #ifdef MON_GROUPING case MON_GROUPING: #endif #ifdef POSITIVE_SIGN case POSITIVE_SIGN: #endif #ifdef NEGATIVE_SIGN case NEGATIVE_SIGN: #endif #ifdef INT_FRAC_DIGITS case INT_FRAC_DIGITS: #endif #ifdef FRAC_DIGITS case FRAC_DIGITS: #endif #ifdef P_CS_PRECEDES case P_CS_PRECEDES: #endif #ifdef P_SEP_BY_SPACE case P_SEP_BY_SPACE: #endif #ifdef N_CS_PRECEDES case N_CS_PRECEDES: #endif #ifdef N_SEP_BY_SPACE case N_SEP_BY_SPACE: #endif #ifdef P_SIGN_POSN case P_SIGN_POSN: #endif #ifdef N_SIGN_POSN case N_SIGN_POSN: #endif #ifdef DECIMAL_POINT case DECIMAL_POINT: #elif defined(RADIXCHAR) case RADIXCHAR: #endif #ifdef THOUSANDS_SEP case THOUSANDS_SEP: #elif defined(THOUSEP) case THOUSEP: #endif #ifdef GROUPING case GROUPING: #endif #ifdef YESEXPR case YESEXPR: #endif #ifdef NOEXPR case NOEXPR: #endif #ifdef YESSTR case YESSTR: #endif #ifdef NOSTR case NOSTR: #endif #ifdef CODESET case CODESET: #endif break; default: php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); RETURN_FALSE; } /* }}} */ value = nl_langinfo(item); if (value == NULL) { RETURN_FALSE; } else { RETURN_STRING(value); } }
Exec Code
0
PHP_FUNCTION(nl_langinfo) { zend_long item; char *value; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &item) == FAILURE) { return; } switch(item) { /* {{{ */ #ifdef ABDAY_1 case ABDAY_1: case ABDAY_2: case ABDAY_3: case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: #endif #ifdef DAY_1 case DAY_1: case DAY_2: case DAY_3: case DAY_4: case DAY_5: case DAY_6: case DAY_7: #endif #ifdef ABMON_1 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: #endif #ifdef MON_1 case MON_1: case MON_2: case MON_3: case MON_4: case MON_5: case MON_6: case MON_7: case MON_8: case MON_9: case MON_10: case MON_11: case MON_12: #endif #ifdef AM_STR case AM_STR: #endif #ifdef PM_STR case PM_STR: #endif #ifdef D_T_FMT case D_T_FMT: #endif #ifdef D_FMT case D_FMT: #endif #ifdef T_FMT case T_FMT: #endif #ifdef T_FMT_AMPM case T_FMT_AMPM: #endif #ifdef ERA case ERA: #endif #ifdef ERA_YEAR case ERA_YEAR: #endif #ifdef ERA_D_T_FMT case ERA_D_T_FMT: #endif #ifdef ERA_D_FMT case ERA_D_FMT: #endif #ifdef ERA_T_FMT case ERA_T_FMT: #endif #ifdef ALT_DIGITS case ALT_DIGITS: #endif #ifdef INT_CURR_SYMBOL case INT_CURR_SYMBOL: #endif #ifdef CURRENCY_SYMBOL case CURRENCY_SYMBOL: #endif #ifdef CRNCYSTR case CRNCYSTR: #endif #ifdef MON_DECIMAL_POINT case MON_DECIMAL_POINT: #endif #ifdef MON_THOUSANDS_SEP case MON_THOUSANDS_SEP: #endif #ifdef MON_GROUPING case MON_GROUPING: #endif #ifdef POSITIVE_SIGN case POSITIVE_SIGN: #endif #ifdef NEGATIVE_SIGN case NEGATIVE_SIGN: #endif #ifdef INT_FRAC_DIGITS case INT_FRAC_DIGITS: #endif #ifdef FRAC_DIGITS case FRAC_DIGITS: #endif #ifdef P_CS_PRECEDES case P_CS_PRECEDES: #endif #ifdef P_SEP_BY_SPACE case P_SEP_BY_SPACE: #endif #ifdef N_CS_PRECEDES case N_CS_PRECEDES: #endif #ifdef N_SEP_BY_SPACE case N_SEP_BY_SPACE: #endif #ifdef P_SIGN_POSN case P_SIGN_POSN: #endif #ifdef N_SIGN_POSN case N_SIGN_POSN: #endif #ifdef DECIMAL_POINT case DECIMAL_POINT: #elif defined(RADIXCHAR) case RADIXCHAR: #endif #ifdef THOUSANDS_SEP case THOUSANDS_SEP: #elif defined(THOUSEP) case THOUSEP: #endif #ifdef GROUPING case GROUPING: #endif #ifdef YESEXPR case YESEXPR: #endif #ifdef NOEXPR case NOEXPR: #endif #ifdef YESSTR case YESSTR: #endif #ifdef NOSTR case NOSTR: #endif #ifdef CODESET case CODESET: #endif break; default: php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); RETURN_FALSE; } /* }}} */ value = nl_langinfo(item); if (value == NULL) { RETURN_FALSE; } else { RETURN_STRING(value); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,729
PHP_FUNCTION(strcoll) { zend_string *s1, *s2; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) { return; } RETURN_LONG(strcoll((const char *) ZSTR_VAL(s1), (const char *) ZSTR_VAL(s2))); }
Exec Code
0
PHP_FUNCTION(strcoll) { zend_string *s1, *s2; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) { return; } RETURN_LONG(strcoll((const char *) ZSTR_VAL(s1), (const char *) ZSTR_VAL(s2))); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,730
PHP_FUNCTION(trim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); }
Exec Code
0
PHP_FUNCTION(trim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,731
PHP_FUNCTION(rtrim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); }
Exec Code
0
PHP_FUNCTION(rtrim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,732
PHP_FUNCTION(ltrim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
Exec Code
0
PHP_FUNCTION(ltrim) { php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,733
PHP_FUNCTION(wordwrap) { zend_string *text; char *breakchar = "\n"; size_t newtextlen, chk, breakchar_len = 1; size_t alloced; zend_long current = 0, laststart = 0, lastspace = 0; zend_long linelength = 75; zend_bool docut = 0; zend_string *newtext; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lsb", &text, &linelength, &breakchar, &breakchar_len, &docut) == FAILURE) { return; } if (ZSTR_LEN(text) == 0) { RETURN_EMPTY_STRING(); } if (breakchar_len == 0) { php_error_docref(NULL, E_WARNING, "Break string cannot be empty"); RETURN_FALSE; } if (linelength == 0 && docut) { php_error_docref(NULL, E_WARNING, "Can't force cut when width is zero"); RETURN_FALSE; } /* Special case for a single-character break as it needs no additional storage space */ if (breakchar_len == 1 && !docut) { newtext = zend_string_init(ZSTR_VAL(text), ZSTR_LEN(text), 0); laststart = lastspace = 0; for (current = 0; current < ZSTR_LEN(text); current++) { if (ZSTR_VAL(text)[current] == breakchar[0]) { laststart = lastspace = current + 1; } else if (ZSTR_VAL(text)[current] == ' ') { if (current - laststart >= linelength) { ZSTR_VAL(newtext)[current] = breakchar[0]; laststart = current + 1; } lastspace = current; } else if (current - laststart >= linelength && laststart != lastspace) { ZSTR_VAL(newtext)[lastspace] = breakchar[0]; laststart = lastspace + 1; } } RETURN_NEW_STR(newtext); } else { /* Multiple character line break or forced cut */ if (linelength > 0) { chk = (size_t)(ZSTR_LEN(text)/linelength + 1); newtext = zend_string_alloc(chk * breakchar_len + ZSTR_LEN(text), 0); alloced = ZSTR_LEN(text) + chk * breakchar_len + 1; } else { chk = ZSTR_LEN(text); alloced = ZSTR_LEN(text) * (breakchar_len + 1) + 1; newtext = zend_string_alloc(ZSTR_LEN(text) * (breakchar_len + 1), 0); } /* now keep track of the actual new text length */ newtextlen = 0; laststart = lastspace = 0; for (current = 0; current < ZSTR_LEN(text); current++) { if (chk <= 0) { alloced += (size_t) (((ZSTR_LEN(text) - current + 1)/linelength + 1) * breakchar_len) + 1; newtext = zend_string_extend(newtext, alloced, 0); chk = (size_t) ((ZSTR_LEN(text) - current)/linelength) + 1; } /* when we hit an existing break, copy to new buffer, and * fix up laststart and lastspace */ if (ZSTR_VAL(text)[current] == breakchar[0] && current + breakchar_len < ZSTR_LEN(text) && !strncmp(ZSTR_VAL(text) + current, breakchar, breakchar_len)) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart + breakchar_len); newtextlen += current - laststart + breakchar_len; current += breakchar_len - 1; laststart = lastspace = current + 1; chk--; } /* if it is a space, check if it is at the line boundary, * copy and insert a break, or just keep track of it */ else if (ZSTR_VAL(text)[current] == ' ') { if (current - laststart >= linelength) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = current + 1; chk--; } lastspace = current; } /* if we are cutting, and we've accumulated enough * characters, and we haven't see a space for this line, * copy and insert a break. */ else if (current - laststart >= linelength && docut && laststart >= lastspace) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = lastspace = current; chk--; } /* if the current word puts us over the linelength, copy * back up until the last space, insert a break, and move * up the laststart */ else if (current - laststart >= linelength && laststart < lastspace) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, lastspace - laststart); newtextlen += lastspace - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = lastspace = lastspace + 1; chk--; } } /* copy over any stragglers */ if (laststart != current) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; } ZSTR_VAL(newtext)[newtextlen] = '\0'; /* free unused memory */ newtext = zend_string_truncate(newtext, newtextlen, 0); RETURN_NEW_STR(newtext); } }
Exec Code
0
PHP_FUNCTION(wordwrap) { zend_string *text; char *breakchar = "\n"; size_t newtextlen, chk, breakchar_len = 1; size_t alloced; zend_long current = 0, laststart = 0, lastspace = 0; zend_long linelength = 75; zend_bool docut = 0; zend_string *newtext; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lsb", &text, &linelength, &breakchar, &breakchar_len, &docut) == FAILURE) { return; } if (ZSTR_LEN(text) == 0) { RETURN_EMPTY_STRING(); } if (breakchar_len == 0) { php_error_docref(NULL, E_WARNING, "Break string cannot be empty"); RETURN_FALSE; } if (linelength == 0 && docut) { php_error_docref(NULL, E_WARNING, "Can't force cut when width is zero"); RETURN_FALSE; } /* Special case for a single-character break as it needs no additional storage space */ if (breakchar_len == 1 && !docut) { newtext = zend_string_init(ZSTR_VAL(text), ZSTR_LEN(text), 0); laststart = lastspace = 0; for (current = 0; current < ZSTR_LEN(text); current++) { if (ZSTR_VAL(text)[current] == breakchar[0]) { laststart = lastspace = current + 1; } else if (ZSTR_VAL(text)[current] == ' ') { if (current - laststart >= linelength) { ZSTR_VAL(newtext)[current] = breakchar[0]; laststart = current + 1; } lastspace = current; } else if (current - laststart >= linelength && laststart != lastspace) { ZSTR_VAL(newtext)[lastspace] = breakchar[0]; laststart = lastspace + 1; } } RETURN_NEW_STR(newtext); } else { /* Multiple character line break or forced cut */ if (linelength > 0) { chk = (size_t)(ZSTR_LEN(text)/linelength + 1); newtext = zend_string_alloc(chk * breakchar_len + ZSTR_LEN(text), 0); alloced = ZSTR_LEN(text) + chk * breakchar_len + 1; } else { chk = ZSTR_LEN(text); alloced = ZSTR_LEN(text) * (breakchar_len + 1) + 1; newtext = zend_string_alloc(ZSTR_LEN(text) * (breakchar_len + 1), 0); } /* now keep track of the actual new text length */ newtextlen = 0; laststart = lastspace = 0; for (current = 0; current < ZSTR_LEN(text); current++) { if (chk <= 0) { alloced += (size_t) (((ZSTR_LEN(text) - current + 1)/linelength + 1) * breakchar_len) + 1; newtext = zend_string_extend(newtext, alloced, 0); chk = (size_t) ((ZSTR_LEN(text) - current)/linelength) + 1; } /* when we hit an existing break, copy to new buffer, and * fix up laststart and lastspace */ if (ZSTR_VAL(text)[current] == breakchar[0] && current + breakchar_len < ZSTR_LEN(text) && !strncmp(ZSTR_VAL(text) + current, breakchar, breakchar_len)) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart + breakchar_len); newtextlen += current - laststart + breakchar_len; current += breakchar_len - 1; laststart = lastspace = current + 1; chk--; } /* if it is a space, check if it is at the line boundary, * copy and insert a break, or just keep track of it */ else if (ZSTR_VAL(text)[current] == ' ') { if (current - laststart >= linelength) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = current + 1; chk--; } lastspace = current; } /* if we are cutting, and we've accumulated enough * characters, and we haven't see a space for this line, * copy and insert a break. */ else if (current - laststart >= linelength && docut && laststart >= lastspace) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = lastspace = current; chk--; } /* if the current word puts us over the linelength, copy * back up until the last space, insert a break, and move * up the laststart */ else if (current - laststart >= linelength && laststart < lastspace) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, lastspace - laststart); newtextlen += lastspace - laststart; memcpy(ZSTR_VAL(newtext) + newtextlen, breakchar, breakchar_len); newtextlen += breakchar_len; laststart = lastspace = lastspace + 1; chk--; } } /* copy over any stragglers */ if (laststart != current) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart); newtextlen += current - laststart; } ZSTR_VAL(newtext)[newtextlen] = '\0'; /* free unused memory */ newtext = zend_string_truncate(newtext, newtextlen, 0); RETURN_NEW_STR(newtext); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,734
PHP_FUNCTION(explode) { zend_string *str, *delim; zend_long limit = ZEND_LONG_MAX; /* No limit */ zval tmp; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &delim, &str, &limit) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(delim) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG(limit) ZEND_PARSE_PARAMETERS_END(); #endif if (ZSTR_LEN(delim) == 0) { php_error_docref(NULL, E_WARNING, "Empty delimiter"); RETURN_FALSE; } array_init(return_value); if (ZSTR_LEN(str) == 0) { if (limit >= 0) { ZVAL_EMPTY_STRING(&tmp); zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp); } return; } if (limit > 1) { php_explode(delim, str, return_value, limit); } else if (limit < 0) { php_explode_negative_limit(delim, str, return_value, limit); } else { ZVAL_STR_COPY(&tmp, str); zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp); } }
Exec Code
0
PHP_FUNCTION(explode) { zend_string *str, *delim; zend_long limit = ZEND_LONG_MAX; /* No limit */ zval tmp; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &delim, &str, &limit) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(delim) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG(limit) ZEND_PARSE_PARAMETERS_END(); #endif if (ZSTR_LEN(delim) == 0) { php_error_docref(NULL, E_WARNING, "Empty delimiter"); RETURN_FALSE; } array_init(return_value); if (ZSTR_LEN(str) == 0) { if (limit >= 0) { ZVAL_EMPTY_STRING(&tmp); zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp); } return; } if (limit > 1) { php_explode(delim, str, return_value, limit); } else if (limit < 0) { php_explode_negative_limit(delim, str, return_value, limit); } else { ZVAL_STR_COPY(&tmp, str); zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,735
PHP_FUNCTION(implode) { zval *arg1, *arg2 = NULL, *arr; zend_string *delim; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|z", &arg1, &arg2) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(arg1) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(arg2) ZEND_PARSE_PARAMETERS_END(); #endif if (arg2 == NULL) { if (Z_TYPE_P(arg1) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "Argument must be an array"); return; } delim = ZSTR_EMPTY_ALLOC(); arr = arg1; } else { if (Z_TYPE_P(arg1) == IS_ARRAY) { delim = zval_get_string(arg2); arr = arg1; } else if (Z_TYPE_P(arg2) == IS_ARRAY) { delim = zval_get_string(arg1); arr = arg2; } else { php_error_docref(NULL, E_WARNING, "Invalid arguments passed"); return; } } php_implode(delim, arr, return_value); zend_string_release(delim); }
Exec Code
0
PHP_FUNCTION(implode) { zval *arg1, *arg2 = NULL, *arr; zend_string *delim; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|z", &arg1, &arg2) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(arg1) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(arg2) ZEND_PARSE_PARAMETERS_END(); #endif if (arg2 == NULL) { if (Z_TYPE_P(arg1) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "Argument must be an array"); return; } delim = ZSTR_EMPTY_ALLOC(); arr = arg1; } else { if (Z_TYPE_P(arg1) == IS_ARRAY) { delim = zval_get_string(arg2); arr = arg1; } else if (Z_TYPE_P(arg2) == IS_ARRAY) { delim = zval_get_string(arg1); arr = arg2; } else { php_error_docref(NULL, E_WARNING, "Invalid arguments passed"); return; } } php_implode(delim, arr, return_value); zend_string_release(delim); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,736
PHP_FUNCTION(strtok) { zend_string *str, *tok = NULL; char *token; char *token_end; char *p; char *pe; size_t skipped = 0; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &str, &tok) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STR(tok) ZEND_PARSE_PARAMETERS_END(); #endif if (ZEND_NUM_ARGS() == 1) { tok = str; } else { zval_ptr_dtor(&BG(strtok_zval)); ZVAL_STRINGL(&BG(strtok_zval), ZSTR_VAL(str), ZSTR_LEN(str)); BG(strtok_last) = BG(strtok_string) = Z_STRVAL(BG(strtok_zval)); BG(strtok_len) = ZSTR_LEN(str); } p = BG(strtok_last); /* Where we start to search */ pe = BG(strtok_string) + BG(strtok_len); if (!p || p >= pe) { RETURN_FALSE; } token = ZSTR_VAL(tok); token_end = token + ZSTR_LEN(tok); while (token < token_end) { STRTOK_TABLE(token++) = 1; } /* Skip leading delimiters */ while (STRTOK_TABLE(p)) { if (++p >= pe) { /* no other chars left */ BG(strtok_last) = NULL; RETVAL_FALSE; goto restore; } skipped++; } /* We know at this place that *p is no delimiter, so skip it */ while (++p < pe) { if (STRTOK_TABLE(p)) { goto return_token; } } if (p - BG(strtok_last)) { return_token: RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped); BG(strtok_last) = p + 1; } else { RETVAL_FALSE; BG(strtok_last) = NULL; } /* Restore table -- usually faster then memset'ing the table on every invocation */ restore: token = ZSTR_VAL(tok); while (token < token_end) { STRTOK_TABLE(token++) = 0; } }
Exec Code
0
PHP_FUNCTION(strtok) { zend_string *str, *tok = NULL; char *token; char *token_end; char *p; char *pe; size_t skipped = 0; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &str, &tok) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STR(tok) ZEND_PARSE_PARAMETERS_END(); #endif if (ZEND_NUM_ARGS() == 1) { tok = str; } else { zval_ptr_dtor(&BG(strtok_zval)); ZVAL_STRINGL(&BG(strtok_zval), ZSTR_VAL(str), ZSTR_LEN(str)); BG(strtok_last) = BG(strtok_string) = Z_STRVAL(BG(strtok_zval)); BG(strtok_len) = ZSTR_LEN(str); } p = BG(strtok_last); /* Where we start to search */ pe = BG(strtok_string) + BG(strtok_len); if (!p || p >= pe) { RETURN_FALSE; } token = ZSTR_VAL(tok); token_end = token + ZSTR_LEN(tok); while (token < token_end) { STRTOK_TABLE(token++) = 1; } /* Skip leading delimiters */ while (STRTOK_TABLE(p)) { if (++p >= pe) { /* no other chars left */ BG(strtok_last) = NULL; RETVAL_FALSE; goto restore; } skipped++; } /* We know at this place that *p is no delimiter, so skip it */ while (++p < pe) { if (STRTOK_TABLE(p)) { goto return_token; } } if (p - BG(strtok_last)) { return_token: RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped); BG(strtok_last) = p + 1; } else { RETVAL_FALSE; BG(strtok_last) = NULL; } /* Restore table -- usually faster then memset'ing the table on every invocation */ restore: token = ZSTR_VAL(tok); while (token < token_end) { STRTOK_TABLE(token++) = 0; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,737
PHP_FUNCTION(strtoupper) { zend_string *arg; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &arg) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(arg) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_STR(php_string_toupper(arg)); }
Exec Code
0
PHP_FUNCTION(strtoupper) { zend_string *arg; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &arg) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(arg) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_STR(php_string_toupper(arg)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,738
PHP_FUNCTION(strtolower) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_STR(php_string_tolower(str)); }
Exec Code
0
PHP_FUNCTION(strtolower) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_STR(php_string_tolower(str)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,739
PHP_FUNCTION(basename) { char *string, *suffix = NULL; size_t string_len, suffix_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &string, &string_len, &suffix, &suffix_len) == FAILURE) { return; } RETURN_STR(php_basename(string, string_len, suffix, suffix_len)); }
Exec Code
0
PHP_FUNCTION(basename) { char *string, *suffix = NULL; size_t string_len, suffix_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &string, &string_len, &suffix, &suffix_len) == FAILURE) { return; } RETURN_STR(php_basename(string, string_len, suffix, suffix_len)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,740
PHP_FUNCTION(dirname) { char *str; zend_string *ret; size_t str_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) { return; } ret = zend_string_init(str, str_len, 0); ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len); RETURN_NEW_STR(ret); }
Exec Code
0
PHP_FUNCTION(dirname) { char *str; zend_string *ret; size_t str_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) { return; } ret = zend_string_init(str, str_len, 0); ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len); RETURN_NEW_STR(ret); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,741
PHP_FUNCTION(stristr) { zval *needle; zend_string *haystack; char *found = NULL; size_t found_offset; char *haystack_dup; char needle_char[2]; zend_bool part = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|b", &haystack, &needle, &part) == FAILURE) { return; } haystack_dup = estrndup(ZSTR_VAL(haystack), ZSTR_LEN(haystack)); if (Z_TYPE_P(needle) == IS_STRING) { char *orig_needle; if (!Z_STRLEN_P(needle)) { php_error_docref(NULL, E_WARNING, "Empty needle"); efree(haystack_dup); RETURN_FALSE; } orig_needle = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); found = php_stristr(haystack_dup, orig_needle, ZSTR_LEN(haystack), Z_STRLEN_P(needle)); efree(orig_needle); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { efree(haystack_dup); RETURN_FALSE; } needle_char[1] = 0; found = php_stristr(haystack_dup, needle_char, ZSTR_LEN(haystack), 1); } if (found) { found_offset = found - haystack_dup; if (part) { RETVAL_STRINGL(ZSTR_VAL(haystack), found_offset); } else { RETVAL_STRINGL(ZSTR_VAL(haystack) + found_offset, ZSTR_LEN(haystack) - found_offset); } } else { RETVAL_FALSE; } efree(haystack_dup); }
Exec Code
0
PHP_FUNCTION(stristr) { zval *needle; zend_string *haystack; char *found = NULL; size_t found_offset; char *haystack_dup; char needle_char[2]; zend_bool part = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|b", &haystack, &needle, &part) == FAILURE) { return; } haystack_dup = estrndup(ZSTR_VAL(haystack), ZSTR_LEN(haystack)); if (Z_TYPE_P(needle) == IS_STRING) { char *orig_needle; if (!Z_STRLEN_P(needle)) { php_error_docref(NULL, E_WARNING, "Empty needle"); efree(haystack_dup); RETURN_FALSE; } orig_needle = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); found = php_stristr(haystack_dup, orig_needle, ZSTR_LEN(haystack), Z_STRLEN_P(needle)); efree(orig_needle); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { efree(haystack_dup); RETURN_FALSE; } needle_char[1] = 0; found = php_stristr(haystack_dup, needle_char, ZSTR_LEN(haystack), 1); } if (found) { found_offset = found - haystack_dup; if (part) { RETVAL_STRINGL(ZSTR_VAL(haystack), found_offset); } else { RETVAL_STRINGL(ZSTR_VAL(haystack) + found_offset, ZSTR_LEN(haystack) - found_offset); } } else { RETVAL_FALSE; } efree(haystack_dup); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,742
PHP_FUNCTION(strpos) { zval *needle; zend_string *haystack; char *found = NULL; char needle_char[2]; zend_long offset = 0; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(haystack) Z_PARAM_ZVAL(needle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) ZEND_PARSE_PARAMETERS_END(); #endif if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } if (Z_TYPE_P(needle) == IS_STRING) { if (!Z_STRLEN_P(needle)) { php_error_docref(NULL, E_WARNING, "Empty needle"); RETURN_FALSE; } found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, Z_STRVAL_P(needle), Z_STRLEN_P(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { RETURN_FALSE; } needle_char[1] = 0; found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, needle_char, 1, ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); } if (found) { RETURN_LONG(found - ZSTR_VAL(haystack)); } else { RETURN_FALSE; } }
Exec Code
0
PHP_FUNCTION(strpos) { zval *needle; zend_string *haystack; char *found = NULL; char needle_char[2]; zend_long offset = 0; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(haystack) Z_PARAM_ZVAL(needle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) ZEND_PARSE_PARAMETERS_END(); #endif if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } if (Z_TYPE_P(needle) == IS_STRING) { if (!Z_STRLEN_P(needle)) { php_error_docref(NULL, E_WARNING, "Empty needle"); RETURN_FALSE; } found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, Z_STRVAL_P(needle), Z_STRLEN_P(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { RETURN_FALSE; } needle_char[1] = 0; found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, needle_char, 1, ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); } if (found) { RETURN_LONG(found - ZSTR_VAL(haystack)); } else { RETURN_FALSE; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,743
PHP_FUNCTION(stripos) { char *found = NULL; zend_string *haystack; zend_long offset = 0; char needle_char[2]; zval *needle; zend_string *needle_dup = NULL, *haystack_dup; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } if (ZSTR_LEN(haystack) == 0) { RETURN_FALSE; } if (Z_TYPE_P(needle) == IS_STRING) { if (Z_STRLEN_P(needle) == 0 || Z_STRLEN_P(needle) > ZSTR_LEN(haystack)) { RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); needle_dup = php_string_tolower(Z_STR_P(needle)); found = (char*)php_memnstr(ZSTR_VAL(haystack_dup) + offset, ZSTR_VAL(needle_dup), ZSTR_LEN(needle_dup), ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack)); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); needle_char[0] = tolower(needle_char[0]); needle_char[1] = '\0'; found = (char*)php_memnstr(ZSTR_VAL(haystack_dup) + offset, needle_char, sizeof(needle_char) - 1, ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack)); } if (found) { RETVAL_LONG(found - ZSTR_VAL(haystack_dup)); } else { RETVAL_FALSE; } zend_string_release(haystack_dup); if (needle_dup) { zend_string_release(needle_dup); } }
Exec Code
0
PHP_FUNCTION(stripos) { char *found = NULL; zend_string *haystack; zend_long offset = 0; char needle_char[2]; zval *needle; zend_string *needle_dup = NULL, *haystack_dup; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } if (offset < 0 || (size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } if (ZSTR_LEN(haystack) == 0) { RETURN_FALSE; } if (Z_TYPE_P(needle) == IS_STRING) { if (Z_STRLEN_P(needle) == 0 || Z_STRLEN_P(needle) > ZSTR_LEN(haystack)) { RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); needle_dup = php_string_tolower(Z_STR_P(needle)); found = (char*)php_memnstr(ZSTR_VAL(haystack_dup) + offset, ZSTR_VAL(needle_dup), ZSTR_LEN(needle_dup), ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack)); } else { if (php_needle_char(needle, needle_char) != SUCCESS) { RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); needle_char[0] = tolower(needle_char[0]); needle_char[1] = '\0'; found = (char*)php_memnstr(ZSTR_VAL(haystack_dup) + offset, needle_char, sizeof(needle_char) - 1, ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack)); } if (found) { RETVAL_LONG(found - ZSTR_VAL(haystack_dup)); } else { RETVAL_FALSE; } zend_string_release(haystack_dup); if (needle_dup) { zend_string_release(needle_dup); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,744
PHP_FUNCTION(strrpos) { zval *zneedle; char *needle; zend_string *haystack; size_t needle_len; zend_long offset = 0; char *p, *e, ord_needle[2]; char *found; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(haystack) Z_PARAM_ZVAL(zneedle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif if (Z_TYPE_P(zneedle) == IS_STRING) { needle = Z_STRVAL_P(zneedle); needle_len = Z_STRLEN_P(zneedle); } else { if (php_needle_char(zneedle, ord_needle) != SUCCESS) { RETURN_FALSE; } ord_needle[1] = '\0'; needle = ord_needle; needle_len = 1; } if ((ZSTR_LEN(haystack) == 0) || (needle_len == 0)) { RETURN_FALSE; } if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack); if (-offset < needle_len) { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) + offset + needle_len; } } if ((found = (char *)zend_memnrstr(p, needle, needle_len, e))) { RETURN_LONG(found - ZSTR_VAL(haystack)); } RETURN_FALSE; }
Exec Code
0
PHP_FUNCTION(strrpos) { zval *zneedle; char *needle; zend_string *haystack; size_t needle_len; zend_long offset = 0; char *p, *e, ord_needle[2]; char *found; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(haystack) Z_PARAM_ZVAL(zneedle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif if (Z_TYPE_P(zneedle) == IS_STRING) { needle = Z_STRVAL_P(zneedle); needle_len = Z_STRLEN_P(zneedle); } else { if (php_needle_char(zneedle, ord_needle) != SUCCESS) { RETURN_FALSE; } ord_needle[1] = '\0'; needle = ord_needle; needle_len = 1; } if ((ZSTR_LEN(haystack) == 0) || (needle_len == 0)) { RETURN_FALSE; } if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack); if (-offset < needle_len) { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) + offset + needle_len; } } if ((found = (char *)zend_memnrstr(p, needle, needle_len, e))) { RETURN_LONG(found - ZSTR_VAL(haystack)); } RETURN_FALSE; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,745
PHP_FUNCTION(strripos) { zval *zneedle; zend_string *needle; zend_string *haystack; zend_long offset = 0; char *p, *e; char *found; zend_string *needle_dup, *haystack_dup, *ord_needle = NULL; ALLOCA_FLAG(use_heap); if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } ZSTR_ALLOCA_ALLOC(ord_needle, 1, use_heap); if (Z_TYPE_P(zneedle) == IS_STRING) { needle = Z_STR_P(zneedle); } else { if (php_needle_char(zneedle, ZSTR_VAL(ord_needle)) != SUCCESS) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } ZSTR_VAL(ord_needle)[1] = '\0'; needle = ord_needle; } if ((ZSTR_LEN(haystack) == 0) || (ZSTR_LEN(needle) == 0)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } if (ZSTR_LEN(needle) == 1) { /* Single character search can shortcut memcmps Can also avoid tolower emallocs */ if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) - 1; } else { p = ZSTR_VAL(haystack); if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) + (size_t)offset; } /* Borrow that ord_needle buffer to avoid repeatedly tolower()ing needle */ *ZSTR_VAL(ord_needle) = tolower(*ZSTR_VAL(needle)); while (e >= p) { if (tolower(*e) == *ZSTR_VAL(ord_needle)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_LONG(e - p + (offset > 0 ? offset : 0)); } e--; } ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack_dup) + offset; e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack_dup); if (-offset < ZSTR_LEN(needle)) { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack) + offset + ZSTR_LEN(needle); } } needle_dup = php_string_tolower(needle); if ((found = (char *)zend_memnrstr(p, ZSTR_VAL(needle_dup), ZSTR_LEN(needle_dup), e))) { RETVAL_LONG(found - ZSTR_VAL(haystack_dup)); zend_string_release(needle_dup); zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); } else { zend_string_release(needle_dup); zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } }
Exec Code
0
PHP_FUNCTION(strripos) { zval *zneedle; zend_string *needle; zend_string *haystack; zend_long offset = 0; char *p, *e; char *found; zend_string *needle_dup, *haystack_dup, *ord_needle = NULL; ALLOCA_FLAG(use_heap); if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } ZSTR_ALLOCA_ALLOC(ord_needle, 1, use_heap); if (Z_TYPE_P(zneedle) == IS_STRING) { needle = Z_STR_P(zneedle); } else { if (php_needle_char(zneedle, ZSTR_VAL(ord_needle)) != SUCCESS) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } ZSTR_VAL(ord_needle)[1] = '\0'; needle = ord_needle; } if ((ZSTR_LEN(haystack) == 0) || (ZSTR_LEN(needle) == 0)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } if (ZSTR_LEN(needle) == 1) { /* Single character search can shortcut memcmps Can also avoid tolower emallocs */ if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack) + (size_t)offset; e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) - 1; } else { p = ZSTR_VAL(haystack); if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) + (size_t)offset; } /* Borrow that ord_needle buffer to avoid repeatedly tolower()ing needle */ *ZSTR_VAL(ord_needle) = tolower(*ZSTR_VAL(needle)); while (e >= p) { if (tolower(*e) == *ZSTR_VAL(ord_needle)) { ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_LONG(e - p + (offset > 0 ? offset : 0)); } e--; } ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } haystack_dup = php_string_tolower(haystack); if (offset >= 0) { if ((size_t)offset > ZSTR_LEN(haystack)) { zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack_dup) + offset; e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { if (offset < -INT_MAX || (size_t)(-offset) > ZSTR_LEN(haystack)) { zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = ZSTR_VAL(haystack_dup); if (-offset < ZSTR_LEN(needle)) { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack) + offset + ZSTR_LEN(needle); } } needle_dup = php_string_tolower(needle); if ((found = (char *)zend_memnrstr(p, ZSTR_VAL(needle_dup), ZSTR_LEN(needle_dup), e))) { RETVAL_LONG(found - ZSTR_VAL(haystack_dup)); zend_string_release(needle_dup); zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); } else { zend_string_release(needle_dup); zend_string_release(haystack_dup); ZSTR_ALLOCA_FREE(ord_needle, use_heap); RETURN_FALSE; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,746
PHP_FUNCTION(strrchr) { zval *needle; zend_string *haystack; const char *found = NULL; zend_long found_offset; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &haystack, &needle) == FAILURE) { return; } if (Z_TYPE_P(needle) == IS_STRING) { found = zend_memrchr(ZSTR_VAL(haystack), *Z_STRVAL_P(needle), ZSTR_LEN(haystack)); } else { char needle_chr; if (php_needle_char(needle, &needle_chr) != SUCCESS) { RETURN_FALSE; } found = zend_memrchr(ZSTR_VAL(haystack), needle_chr, ZSTR_LEN(haystack)); } if (found) { found_offset = found - ZSTR_VAL(haystack); RETURN_STRINGL(found, ZSTR_LEN(haystack) - found_offset); } else { RETURN_FALSE; } }
Exec Code
0
PHP_FUNCTION(strrchr) { zval *needle; zend_string *haystack; const char *found = NULL; zend_long found_offset; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &haystack, &needle) == FAILURE) { return; } if (Z_TYPE_P(needle) == IS_STRING) { found = zend_memrchr(ZSTR_VAL(haystack), *Z_STRVAL_P(needle), ZSTR_LEN(haystack)); } else { char needle_chr; if (php_needle_char(needle, &needle_chr) != SUCCESS) { RETURN_FALSE; } found = zend_memrchr(ZSTR_VAL(haystack), needle_chr, ZSTR_LEN(haystack)); } if (found) { found_offset = found - ZSTR_VAL(haystack); RETURN_STRINGL(found, ZSTR_LEN(haystack) - found_offset); } else { RETURN_FALSE; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,747
PHP_FUNCTION(chunk_split) { zend_string *str; char *end = "\r\n"; size_t endlen = 2; zend_long chunklen = 76; zend_string *result; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls", &str, &chunklen, &end, &endlen) == FAILURE) { return; } if (chunklen <= 0) { php_error_docref(NULL, E_WARNING, "Chunk length should be greater than zero"); RETURN_FALSE; } if ((size_t)chunklen > ZSTR_LEN(str)) { /* to maintain BC, we must return original string + ending */ result = zend_string_alloc(endlen + ZSTR_LEN(str), 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(str), ZSTR_LEN(str)); memcpy(ZSTR_VAL(result) + ZSTR_LEN(str), end, endlen); ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); } if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } result = php_chunk_split(ZSTR_VAL(str), ZSTR_LEN(str), end, endlen, (size_t)chunklen); if (result) { RETURN_STR(result); } else { RETURN_FALSE; } }
Exec Code
0
PHP_FUNCTION(chunk_split) { zend_string *str; char *end = "\r\n"; size_t endlen = 2; zend_long chunklen = 76; zend_string *result; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls", &str, &chunklen, &end, &endlen) == FAILURE) { return; } if (chunklen <= 0) { php_error_docref(NULL, E_WARNING, "Chunk length should be greater than zero"); RETURN_FALSE; } if ((size_t)chunklen > ZSTR_LEN(str)) { /* to maintain BC, we must return original string + ending */ result = zend_string_alloc(endlen + ZSTR_LEN(str), 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(str), ZSTR_LEN(str)); memcpy(ZSTR_VAL(result) + ZSTR_LEN(str), end, endlen); ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); } if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } result = php_chunk_split(ZSTR_VAL(str), ZSTR_LEN(str), end, endlen, (size_t)chunklen); if (result) { RETURN_STR(result); } else { RETURN_FALSE; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,748
PHP_FUNCTION(substr_replace) { zval *str; zval *from; zval *len = NULL; zval *repl; zend_long l = 0; zend_long f; int argc = ZEND_NUM_ARGS(); zend_string *result; HashPosition from_idx, repl_idx, len_idx; zval *tmp_str = NULL, *tmp_from = NULL, *tmp_repl = NULL, *tmp_len= NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z/", &str, &repl, &from, &len) == FAILURE) { return; } if (Z_TYPE_P(str) != IS_ARRAY) { convert_to_string_ex(str); } if (Z_TYPE_P(repl) != IS_ARRAY) { convert_to_string_ex(repl); } if (Z_TYPE_P(from) != IS_ARRAY) { convert_to_long_ex(from); } if (argc > 3) { if (Z_TYPE_P(len) != IS_ARRAY) { l = zval_get_long(len); } } else { if (Z_TYPE_P(str) != IS_ARRAY) { l = Z_STRLEN_P(str); } } if (Z_TYPE_P(str) == IS_STRING) { if ( (argc == 3 && Z_TYPE_P(from) == IS_ARRAY) || (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); RETURN_STR_COPY(Z_STR_P(str)); } if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should have the same number of elements"); RETURN_STR_COPY(Z_STR_P(str)); } } } if (Z_TYPE_P(str) != IS_ARRAY) { if (Z_TYPE_P(from) != IS_ARRAY) { size_t repl_len = 0; f = Z_LVAL_P(from); /* if "from" position is negative, count start position from the end * of the string */ if (f < 0) { f = (zend_long)Z_STRLEN_P(str) + f; if (f < 0) { f = 0; } } else if (f > Z_STRLEN_P(str)) { f = Z_STRLEN_P(str); } /* if "length" position is negative, set it to the length * needed to stop that many chars from the end of the string */ if (l < 0) { l = ((zend_long)Z_STRLEN_P(str) - f) + l; if (l < 0) { l = 0; } } if (l > Z_STRLEN_P(str) || (l < 0 && (size_t)(-l) > Z_STRLEN_P(str))) { l = Z_STRLEN_P(str); } if ((f + l) > (zend_long)Z_STRLEN_P(str)) { l = Z_STRLEN_P(str) - f; } if (Z_TYPE_P(repl) == IS_ARRAY) { repl_idx = 0; while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { break; } repl_idx++; } if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { convert_to_string_ex(tmp_repl); repl_len = Z_STRLEN_P(tmp_repl); } } else { repl_len = Z_STRLEN_P(repl); } result = zend_string_alloc(Z_STRLEN_P(str) - l + repl_len, 0); memcpy(ZSTR_VAL(result), Z_STRVAL_P(str), f); if (repl_len) { memcpy((ZSTR_VAL(result) + f), (Z_TYPE_P(repl) == IS_ARRAY ? Z_STRVAL_P(tmp_repl) : Z_STRVAL_P(repl)), repl_len); } memcpy((ZSTR_VAL(result) + f + repl_len), Z_STRVAL_P(str) + f + l, Z_STRLEN_P(str) - f - l); ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); } else { php_error_docref(NULL, E_WARNING, "Functionality of 'from' and 'len' as arrays is not implemented"); RETURN_STR_COPY(Z_STR_P(str)); } } else { /* str is array of strings */ zend_string *str_index = NULL; size_t result_len; zend_ulong num_index; array_init(return_value); from_idx = len_idx = repl_idx = 0; ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(str), num_index, str_index, tmp_str) { zend_string *orig_str = zval_get_string(tmp_str); if (Z_TYPE_P(from) == IS_ARRAY) { while (from_idx < Z_ARRVAL_P(from)->nNumUsed) { tmp_from = &Z_ARRVAL_P(from)->arData[from_idx].val; if (Z_TYPE_P(tmp_from) != IS_UNDEF) { break; } from_idx++; } if (from_idx < Z_ARRVAL_P(from)->nNumUsed) { f = zval_get_long(tmp_from); if (f < 0) { f = (zend_long)ZSTR_LEN(orig_str) + f; if (f < 0) { f = 0; } } else if (f > (zend_long)ZSTR_LEN(orig_str)) { f = ZSTR_LEN(orig_str); } from_idx++; } else { f = 0; } } else { f = Z_LVAL_P(from); if (f < 0) { f = (zend_long)ZSTR_LEN(orig_str) + f; if (f < 0) { f = 0; } } else if (f > (zend_long)ZSTR_LEN(orig_str)) { f = ZSTR_LEN(orig_str); } } if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { while (len_idx < Z_ARRVAL_P(len)->nNumUsed) { tmp_len = &Z_ARRVAL_P(len)->arData[len_idx].val; if (Z_TYPE_P(tmp_len) != IS_UNDEF) { break; } len_idx++; } if (len_idx < Z_ARRVAL_P(len)->nNumUsed) { l = zval_get_long(tmp_len); len_idx++; } else { l = ZSTR_LEN(orig_str); } } else if (argc > 3) { l = Z_LVAL_P(len); } else { l = ZSTR_LEN(orig_str); } if (l < 0) { l = (ZSTR_LEN(orig_str) - f) + l; if (l < 0) { l = 0; } } if ((f + l) > (zend_long)ZSTR_LEN(orig_str)) { l = ZSTR_LEN(orig_str) - f; } result_len = ZSTR_LEN(orig_str) - l; if (Z_TYPE_P(repl) == IS_ARRAY) { while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { break; } repl_idx++; } if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { zend_string *repl_str = zval_get_string(tmp_repl); result_len += ZSTR_LEN(repl_str); repl_idx++; result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), ZSTR_VAL(repl_str), ZSTR_LEN(repl_str)); memcpy((ZSTR_VAL(result) + f + ZSTR_LEN(repl_str)), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); zend_string_release(repl_str); } else { result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); } } else { result_len += Z_STRLEN_P(repl); result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), Z_STRVAL_P(repl), Z_STRLEN_P(repl)); memcpy((ZSTR_VAL(result) + f + Z_STRLEN_P(repl)), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); } ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; if (str_index) { zval tmp; ZVAL_NEW_STR(&tmp, result); zend_symtable_update(Z_ARRVAL_P(return_value), str_index, &tmp); } else { add_index_str(return_value, num_index, result); } zend_string_release(orig_str); } ZEND_HASH_FOREACH_END(); } /* if */ }
Exec Code
0
PHP_FUNCTION(substr_replace) { zval *str; zval *from; zval *len = NULL; zval *repl; zend_long l = 0; zend_long f; int argc = ZEND_NUM_ARGS(); zend_string *result; HashPosition from_idx, repl_idx, len_idx; zval *tmp_str = NULL, *tmp_from = NULL, *tmp_repl = NULL, *tmp_len= NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z/", &str, &repl, &from, &len) == FAILURE) { return; } if (Z_TYPE_P(str) != IS_ARRAY) { convert_to_string_ex(str); } if (Z_TYPE_P(repl) != IS_ARRAY) { convert_to_string_ex(repl); } if (Z_TYPE_P(from) != IS_ARRAY) { convert_to_long_ex(from); } if (argc > 3) { if (Z_TYPE_P(len) != IS_ARRAY) { l = zval_get_long(len); } } else { if (Z_TYPE_P(str) != IS_ARRAY) { l = Z_STRLEN_P(str); } } if (Z_TYPE_P(str) == IS_STRING) { if ( (argc == 3 && Z_TYPE_P(from) == IS_ARRAY) || (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); RETURN_STR_COPY(Z_STR_P(str)); } if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should have the same number of elements"); RETURN_STR_COPY(Z_STR_P(str)); } } } if (Z_TYPE_P(str) != IS_ARRAY) { if (Z_TYPE_P(from) != IS_ARRAY) { size_t repl_len = 0; f = Z_LVAL_P(from); /* if "from" position is negative, count start position from the end * of the string */ if (f < 0) { f = (zend_long)Z_STRLEN_P(str) + f; if (f < 0) { f = 0; } } else if (f > Z_STRLEN_P(str)) { f = Z_STRLEN_P(str); } /* if "length" position is negative, set it to the length * needed to stop that many chars from the end of the string */ if (l < 0) { l = ((zend_long)Z_STRLEN_P(str) - f) + l; if (l < 0) { l = 0; } } if (l > Z_STRLEN_P(str) || (l < 0 && (size_t)(-l) > Z_STRLEN_P(str))) { l = Z_STRLEN_P(str); } if ((f + l) > (zend_long)Z_STRLEN_P(str)) { l = Z_STRLEN_P(str) - f; } if (Z_TYPE_P(repl) == IS_ARRAY) { repl_idx = 0; while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { break; } repl_idx++; } if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { convert_to_string_ex(tmp_repl); repl_len = Z_STRLEN_P(tmp_repl); } } else { repl_len = Z_STRLEN_P(repl); } result = zend_string_alloc(Z_STRLEN_P(str) - l + repl_len, 0); memcpy(ZSTR_VAL(result), Z_STRVAL_P(str), f); if (repl_len) { memcpy((ZSTR_VAL(result) + f), (Z_TYPE_P(repl) == IS_ARRAY ? Z_STRVAL_P(tmp_repl) : Z_STRVAL_P(repl)), repl_len); } memcpy((ZSTR_VAL(result) + f + repl_len), Z_STRVAL_P(str) + f + l, Z_STRLEN_P(str) - f - l); ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); } else { php_error_docref(NULL, E_WARNING, "Functionality of 'from' and 'len' as arrays is not implemented"); RETURN_STR_COPY(Z_STR_P(str)); } } else { /* str is array of strings */ zend_string *str_index = NULL; size_t result_len; zend_ulong num_index; array_init(return_value); from_idx = len_idx = repl_idx = 0; ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(str), num_index, str_index, tmp_str) { zend_string *orig_str = zval_get_string(tmp_str); if (Z_TYPE_P(from) == IS_ARRAY) { while (from_idx < Z_ARRVAL_P(from)->nNumUsed) { tmp_from = &Z_ARRVAL_P(from)->arData[from_idx].val; if (Z_TYPE_P(tmp_from) != IS_UNDEF) { break; } from_idx++; } if (from_idx < Z_ARRVAL_P(from)->nNumUsed) { f = zval_get_long(tmp_from); if (f < 0) { f = (zend_long)ZSTR_LEN(orig_str) + f; if (f < 0) { f = 0; } } else if (f > (zend_long)ZSTR_LEN(orig_str)) { f = ZSTR_LEN(orig_str); } from_idx++; } else { f = 0; } } else { f = Z_LVAL_P(from); if (f < 0) { f = (zend_long)ZSTR_LEN(orig_str) + f; if (f < 0) { f = 0; } } else if (f > (zend_long)ZSTR_LEN(orig_str)) { f = ZSTR_LEN(orig_str); } } if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { while (len_idx < Z_ARRVAL_P(len)->nNumUsed) { tmp_len = &Z_ARRVAL_P(len)->arData[len_idx].val; if (Z_TYPE_P(tmp_len) != IS_UNDEF) { break; } len_idx++; } if (len_idx < Z_ARRVAL_P(len)->nNumUsed) { l = zval_get_long(tmp_len); len_idx++; } else { l = ZSTR_LEN(orig_str); } } else if (argc > 3) { l = Z_LVAL_P(len); } else { l = ZSTR_LEN(orig_str); } if (l < 0) { l = (ZSTR_LEN(orig_str) - f) + l; if (l < 0) { l = 0; } } if ((f + l) > (zend_long)ZSTR_LEN(orig_str)) { l = ZSTR_LEN(orig_str) - f; } result_len = ZSTR_LEN(orig_str) - l; if (Z_TYPE_P(repl) == IS_ARRAY) { while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { break; } repl_idx++; } if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { zend_string *repl_str = zval_get_string(tmp_repl); result_len += ZSTR_LEN(repl_str); repl_idx++; result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), ZSTR_VAL(repl_str), ZSTR_LEN(repl_str)); memcpy((ZSTR_VAL(result) + f + ZSTR_LEN(repl_str)), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); zend_string_release(repl_str); } else { result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); } } else { result_len += Z_STRLEN_P(repl); result = zend_string_alloc(result_len, 0); memcpy(ZSTR_VAL(result), ZSTR_VAL(orig_str), f); memcpy((ZSTR_VAL(result) + f), Z_STRVAL_P(repl), Z_STRLEN_P(repl)); memcpy((ZSTR_VAL(result) + f + Z_STRLEN_P(repl)), ZSTR_VAL(orig_str) + f + l, ZSTR_LEN(orig_str) - f - l); } ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; if (str_index) { zval tmp; ZVAL_NEW_STR(&tmp, result); zend_symtable_update(Z_ARRVAL_P(return_value), str_index, &tmp); } else { add_index_str(return_value, num_index, result); } zend_string_release(orig_str); } ZEND_HASH_FOREACH_END(); } /* if */ }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,749
PHP_FUNCTION(ord) { char *str; size_t str_len; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(str, str_len) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_LONG((unsigned char) str[0]); }
Exec Code
0
PHP_FUNCTION(ord) { char *str; size_t str_len; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(str, str_len) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_LONG((unsigned char) str[0]); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,750
PHP_FUNCTION(chr) { zend_long c; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } #ifndef FAST_ZPP if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "l", &c) == FAILURE) { c = 0; } #else ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1) Z_PARAM_LONG(c) ZEND_PARSE_PARAMETERS_END_EX(c = 0); #endif c &= 0xff; if (CG(one_char_string)[c]) { ZVAL_INTERNED_STR(return_value, CG(one_char_string)[c]); } else { ZVAL_NEW_STR(return_value, zend_string_alloc(1, 0)); Z_STRVAL_P(return_value)[0] = (char)c; Z_STRVAL_P(return_value)[1] = '\0'; } }
Exec Code
0
PHP_FUNCTION(chr) { zend_long c; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } #ifndef FAST_ZPP if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "l", &c) == FAILURE) { c = 0; } #else ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1) Z_PARAM_LONG(c) ZEND_PARSE_PARAMETERS_END_EX(c = 0); #endif c &= 0xff; if (CG(one_char_string)[c]) { ZVAL_INTERNED_STR(return_value, CG(one_char_string)[c]); } else { ZVAL_NEW_STR(return_value, zend_string_alloc(1, 0)); Z_STRVAL_P(return_value)[0] = (char)c; Z_STRVAL_P(return_value)[1] = '\0'; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,751
PHP_FUNCTION(ucfirst) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_ucfirst(Z_STRVAL_P(return_value)); }
Exec Code
0
PHP_FUNCTION(ucfirst) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_ucfirst(Z_STRVAL_P(return_value)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,752
PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, *r_end; size_t delims_len = 6; char mask[256]; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s", &str, &delims, &delims_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STRING(delims, delims_len) ZEND_PARSE_PARAMETERS_END(); #endif if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } php_charmask((unsigned char *)delims, delims_len, mask); ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); r = Z_STRVAL_P(return_value); *r = toupper((unsigned char) *r); for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) { if (mask[(unsigned char)*r++]) { *r = toupper((unsigned char) *r); } } }
Exec Code
0
PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, *r_end; size_t delims_len = 6; char mask[256]; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s", &str, &delims, &delims_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STRING(delims, delims_len) ZEND_PARSE_PARAMETERS_END(); #endif if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } php_charmask((unsigned char *)delims, delims_len, mask); ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); r = Z_STRVAL_P(return_value); *r = toupper((unsigned char) *r); for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) { if (mask[(unsigned char)*r++]) { *r = toupper((unsigned char) *r); } } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,753
PHP_FUNCTION(strtr) { zval *from; zend_string *str; char *to = NULL; size_t to_len = 0; int ac = ZEND_NUM_ARGS(); #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|s", &str, &from, &to, &to_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(str) Z_PARAM_ZVAL(from) Z_PARAM_OPTIONAL Z_PARAM_STRING(to, to_len) ZEND_PARSE_PARAMETERS_END(); #endif if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "The second argument is not an array"); RETURN_FALSE; } /* shortcut for empty string */ if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } if (ac == 2) { HashTable *pats = HASH_OF(from); if (zend_hash_num_elements(pats) < 1) { RETURN_STR_COPY(str); } else if (zend_hash_num_elements(pats) == 1) { zend_long num_key; zend_string *str_key, *replace; zval *entry, tmp; ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { ZVAL_UNDEF(&tmp); if (UNEXPECTED(!str_key)) { ZVAL_LONG(&tmp, num_key); convert_to_string(&tmp); str_key = Z_STR(tmp); } replace = zval_get_string(entry); if (ZSTR_LEN(str_key) < 1) { RETVAL_STR_COPY(str); } else if (ZSTR_LEN(str_key) == 1) { RETVAL_STR(php_char_to_str_ex(str, ZSTR_VAL(str_key)[0], ZSTR_VAL(replace), ZSTR_LEN(replace), 1, NULL)); } else { zend_long dummy; RETVAL_STR(php_str_to_str_ex(str, ZSTR_VAL(str_key), ZSTR_LEN(str_key), ZSTR_VAL(replace), ZSTR_LEN(replace), &dummy)); } zend_string_release(replace); zval_dtor(&tmp); return; } ZEND_HASH_FOREACH_END(); } else { php_strtr_array(return_value, str, pats); } } else { convert_to_string_ex(from); RETURN_STR(php_strtr_ex(str, Z_STRVAL_P(from), to, MIN(Z_STRLEN_P(from), to_len))); } }
Exec Code
0
PHP_FUNCTION(strtr) { zval *from; zend_string *str; char *to = NULL; size_t to_len = 0; int ac = ZEND_NUM_ARGS(); #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|s", &str, &from, &to, &to_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(str) Z_PARAM_ZVAL(from) Z_PARAM_OPTIONAL Z_PARAM_STRING(to, to_len) ZEND_PARSE_PARAMETERS_END(); #endif if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "The second argument is not an array"); RETURN_FALSE; } /* shortcut for empty string */ if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } if (ac == 2) { HashTable *pats = HASH_OF(from); if (zend_hash_num_elements(pats) < 1) { RETURN_STR_COPY(str); } else if (zend_hash_num_elements(pats) == 1) { zend_long num_key; zend_string *str_key, *replace; zval *entry, tmp; ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { ZVAL_UNDEF(&tmp); if (UNEXPECTED(!str_key)) { ZVAL_LONG(&tmp, num_key); convert_to_string(&tmp); str_key = Z_STR(tmp); } replace = zval_get_string(entry); if (ZSTR_LEN(str_key) < 1) { RETVAL_STR_COPY(str); } else if (ZSTR_LEN(str_key) == 1) { RETVAL_STR(php_char_to_str_ex(str, ZSTR_VAL(str_key)[0], ZSTR_VAL(replace), ZSTR_LEN(replace), 1, NULL)); } else { zend_long dummy; RETVAL_STR(php_str_to_str_ex(str, ZSTR_VAL(str_key), ZSTR_LEN(str_key), ZSTR_VAL(replace), ZSTR_LEN(replace), &dummy)); } zend_string_release(replace); zval_dtor(&tmp); return; } ZEND_HASH_FOREACH_END(); } else { php_strtr_array(return_value, str, pats); } } else { convert_to_string_ex(from); RETURN_STR(php_strtr_ex(str, Z_STRVAL_P(from), to, MIN(Z_STRLEN_P(from), to_len))); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,754
PHP_FUNCTION(strrev) { zend_string *str; char *e, *p; zend_string *n; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } n = zend_string_alloc(ZSTR_LEN(str), 0); p = ZSTR_VAL(n); e = ZSTR_VAL(str) + ZSTR_LEN(str); while (--e >= ZSTR_VAL(str)) { *p++ = *e; } *p = '\0'; RETVAL_NEW_STR(n); }
Exec Code
0
PHP_FUNCTION(strrev) { zend_string *str; char *e, *p; zend_string *n; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } n = zend_string_alloc(ZSTR_LEN(str), 0); p = ZSTR_VAL(n); e = ZSTR_VAL(str) + ZSTR_LEN(str); while (--e >= ZSTR_VAL(str)) { *p++ = *e; } *p = '\0'; RETVAL_NEW_STR(n); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,755
PHP_FUNCTION(similar_text) { zend_string *t1, *t2; zval *percent = NULL; int ac = ZEND_NUM_ARGS(); size_t sim; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|z/", &t1, &t2, &percent) == FAILURE) { return; } if (ac > 2) { convert_to_double_ex(percent); } if (ZSTR_LEN(t1) + ZSTR_LEN(t2) == 0) { if (ac > 2) { Z_DVAL_P(percent) = 0; } RETURN_LONG(0); } sim = php_similar_char(ZSTR_VAL(t1), ZSTR_LEN(t1), ZSTR_VAL(t2), ZSTR_LEN(t2)); if (ac > 2) { Z_DVAL_P(percent) = sim * 200.0 / (ZSTR_LEN(t1) + ZSTR_LEN(t2)); } RETURN_LONG(sim); }
Exec Code
0
PHP_FUNCTION(similar_text) { zend_string *t1, *t2; zval *percent = NULL; int ac = ZEND_NUM_ARGS(); size_t sim; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|z/", &t1, &t2, &percent) == FAILURE) { return; } if (ac > 2) { convert_to_double_ex(percent); } if (ZSTR_LEN(t1) + ZSTR_LEN(t2) == 0) { if (ac > 2) { Z_DVAL_P(percent) = 0; } RETURN_LONG(0); } sim = php_similar_char(ZSTR_VAL(t1), ZSTR_LEN(t1), ZSTR_VAL(t2), ZSTR_LEN(t2)); if (ac > 2) { Z_DVAL_P(percent) = sim * 200.0 / (ZSTR_LEN(t1) + ZSTR_LEN(t2)); } RETURN_LONG(sim); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,756
PHP_FUNCTION(addcslashes) { zend_string *str, *what; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &str, &what) == FAILURE) { return; } if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } if (ZSTR_LEN(what) == 0) { RETURN_STRINGL(ZSTR_VAL(str), ZSTR_LEN(str)); } RETURN_STR(php_addcslashes(str, 0, ZSTR_VAL(what), ZSTR_LEN(what))); }
Exec Code
0
PHP_FUNCTION(addcslashes) { zend_string *str, *what; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &str, &what) == FAILURE) { return; } if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } if (ZSTR_LEN(what) == 0) { RETURN_STRINGL(ZSTR_VAL(str), ZSTR_LEN(str)); } RETURN_STR(php_addcslashes(str, 0, ZSTR_VAL(what), ZSTR_LEN(what))); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,757
PHP_FUNCTION(addslashes) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } RETURN_STR(php_addslashes(str, 0)); }
Exec Code
0
PHP_FUNCTION(addslashes) { zend_string *str; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif if (ZSTR_LEN(str) == 0) { RETURN_EMPTY_STRING(); } RETURN_STR(php_addslashes(str, 0)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,758
PHP_FUNCTION(stripcslashes) { zend_string *str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_stripcslashes(Z_STR_P(return_value)); }
Exec Code
0
PHP_FUNCTION(stripcslashes) { zend_string *str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_stripcslashes(Z_STR_P(return_value)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,759
PHP_FUNCTION(stripslashes) { zend_string *str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_stripslashes(Z_STR_P(return_value)); }
Exec Code
0
PHP_FUNCTION(stripslashes) { zend_string *str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } ZVAL_STRINGL(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); php_stripslashes(Z_STR_P(return_value)); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,760
PHP_FUNCTION(str_ireplace) { php_str_replace_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); }
Exec Code
0
PHP_FUNCTION(str_ireplace) { php_str_replace_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,761
PHP_FUNCTION(hebrevc) { php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
Exec Code
0
PHP_FUNCTION(hebrevc) { php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,762
PHP_FUNCTION(nl2br) { /* in brief this inserts <br /> or <br> before matched regexp \n\r?|\r\n? */ char *tmp; zend_string *str; char *end, *target; size_t repl_cnt = 0; zend_bool is_xhtml = 1; zend_string *result; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &str, &is_xhtml) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_BOOL(is_xhtml) ZEND_PARSE_PARAMETERS_END(); #endif tmp = ZSTR_VAL(str); end = ZSTR_VAL(str) + ZSTR_LEN(str); /* it is really faster to scan twice and allocate mem once instead of scanning once and constantly reallocing */ while (tmp < end) { if (*tmp == '\r') { if (*(tmp+1) == '\n') { tmp++; } repl_cnt++; } else if (*tmp == '\n') { if (*(tmp+1) == '\r') { tmp++; } repl_cnt++; } tmp++; } if (repl_cnt == 0) { RETURN_STR_COPY(str); } { size_t repl_len = is_xhtml ? (sizeof("<br />") - 1) : (sizeof("<br>") - 1); result = zend_string_alloc(repl_cnt * repl_len + ZSTR_LEN(str), 0); target = ZSTR_VAL(result); } tmp = ZSTR_VAL(str); while (tmp < end) { switch (*tmp) { case '\r': case '\n': *target++ = '<'; *target++ = 'b'; *target++ = 'r'; if (is_xhtml) { *target++ = ' '; *target++ = '/'; } *target++ = '>'; if ((*tmp == '\r' && *(tmp+1) == '\n') || (*tmp == '\n' && *(tmp+1) == '\r')) { *target++ = *tmp++; } /* lack of a break; is intentional */ default: *target++ = *tmp; } tmp++; } *target = '\0'; RETURN_NEW_STR(result); }
Exec Code
0
PHP_FUNCTION(nl2br) { /* in brief this inserts <br /> or <br> before matched regexp \n\r?|\r\n? */ char *tmp; zend_string *str; char *end, *target; size_t repl_cnt = 0; zend_bool is_xhtml = 1; zend_string *result; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &str, &is_xhtml) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_BOOL(is_xhtml) ZEND_PARSE_PARAMETERS_END(); #endif tmp = ZSTR_VAL(str); end = ZSTR_VAL(str) + ZSTR_LEN(str); /* it is really faster to scan twice and allocate mem once instead of scanning once and constantly reallocing */ while (tmp < end) { if (*tmp == '\r') { if (*(tmp+1) == '\n') { tmp++; } repl_cnt++; } else if (*tmp == '\n') { if (*(tmp+1) == '\r') { tmp++; } repl_cnt++; } tmp++; } if (repl_cnt == 0) { RETURN_STR_COPY(str); } { size_t repl_len = is_xhtml ? (sizeof("<br />") - 1) : (sizeof("<br>") - 1); result = zend_string_alloc(repl_cnt * repl_len + ZSTR_LEN(str), 0); target = ZSTR_VAL(result); } tmp = ZSTR_VAL(str); while (tmp < end) { switch (*tmp) { case '\r': case '\n': *target++ = '<'; *target++ = 'b'; *target++ = 'r'; if (is_xhtml) { *target++ = ' '; *target++ = '/'; } *target++ = '>'; if ((*tmp == '\r' && *(tmp+1) == '\n') || (*tmp == '\n' && *(tmp+1) == '\r')) { *target++ = *tmp++; } /* lack of a break; is intentional */ default: *target++ = *tmp; } tmp++; } *target = '\0'; RETURN_NEW_STR(result); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,763
PHP_FUNCTION(setlocale) { zval *args = NULL; zval *plocale; zend_string *loc; char *retval; zend_long cat; int num_args, i = 0; uint32_t idx; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l+", &cat, &args, &num_args) == FAILURE) { return; } #ifdef HAVE_SETLOCALE idx = 0; while (1) { if (Z_TYPE(args[0]) == IS_ARRAY) { while (idx < Z_ARRVAL(args[0])->nNumUsed) { plocale = &Z_ARRVAL(args[0])->arData[idx].val; if (Z_TYPE_P(plocale) != IS_UNDEF) { break; } idx++; } if (idx >= Z_ARRVAL(args[0])->nNumUsed) { break; } } else { plocale = &args[i]; } loc = zval_get_string(plocale); if (!strcmp("0", ZSTR_VAL(loc))) { zend_string_release(loc); loc = NULL; } else { if (ZSTR_LEN(loc) >= 255) { php_error_docref(NULL, E_WARNING, "Specified locale name is too long"); zend_string_release(loc); break; } } retval = php_my_setlocale(cat, loc ? ZSTR_VAL(loc) : NULL); zend_update_current_locale(); if (retval) { if (loc) { /* Remember if locale was changed */ size_t len = strlen(retval); BG(locale_changed) = 1; if (cat == LC_CTYPE || cat == LC_ALL) { if (BG(locale_string)) { zend_string_release(BG(locale_string)); } if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { BG(locale_string) = zend_string_copy(loc); RETURN_STR(BG(locale_string)); } else { BG(locale_string) = zend_string_init(retval, len, 0); zend_string_release(loc); RETURN_STR_COPY(BG(locale_string)); } } else if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { RETURN_STR(loc); } zend_string_release(loc); } RETURN_STRING(retval); } if (loc) { zend_string_release(loc); } if (Z_TYPE(args[0]) == IS_ARRAY) { idx++; } else { if (++i >= num_args) break; } } #endif RETURN_FALSE; }
Exec Code
0
PHP_FUNCTION(setlocale) { zval *args = NULL; zval *plocale; zend_string *loc; char *retval; zend_long cat; int num_args, i = 0; uint32_t idx; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l+", &cat, &args, &num_args) == FAILURE) { return; } #ifdef HAVE_SETLOCALE idx = 0; while (1) { if (Z_TYPE(args[0]) == IS_ARRAY) { while (idx < Z_ARRVAL(args[0])->nNumUsed) { plocale = &Z_ARRVAL(args[0])->arData[idx].val; if (Z_TYPE_P(plocale) != IS_UNDEF) { break; } idx++; } if (idx >= Z_ARRVAL(args[0])->nNumUsed) { break; } } else { plocale = &args[i]; } loc = zval_get_string(plocale); if (!strcmp("0", ZSTR_VAL(loc))) { zend_string_release(loc); loc = NULL; } else { if (ZSTR_LEN(loc) >= 255) { php_error_docref(NULL, E_WARNING, "Specified locale name is too long"); zend_string_release(loc); break; } } retval = php_my_setlocale(cat, loc ? ZSTR_VAL(loc) : NULL); zend_update_current_locale(); if (retval) { if (loc) { /* Remember if locale was changed */ size_t len = strlen(retval); BG(locale_changed) = 1; if (cat == LC_CTYPE || cat == LC_ALL) { if (BG(locale_string)) { zend_string_release(BG(locale_string)); } if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { BG(locale_string) = zend_string_copy(loc); RETURN_STR(BG(locale_string)); } else { BG(locale_string) = zend_string_init(retval, len, 0); zend_string_release(loc); RETURN_STR_COPY(BG(locale_string)); } } else if (len == ZSTR_LEN(loc) && !memcmp(ZSTR_VAL(loc), retval, len)) { RETURN_STR(loc); } zend_string_release(loc); } RETURN_STRING(retval); } if (loc) { zend_string_release(loc); } if (Z_TYPE(args[0]) == IS_ARRAY) { idx++; } else { if (++i >= num_args) break; } } #endif RETURN_FALSE; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,764
PHP_FUNCTION(parse_str) { char *arg; zval *arrayArg = NULL; char *res = NULL; size_t arglen; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z/", &arg, &arglen, &arrayArg) == FAILURE) { return; } res = estrndup(arg, arglen); if (arrayArg == NULL) { zval tmp; zend_array *symbol_table = zend_rebuild_symbol_table(); ZVAL_ARR(&tmp, symbol_table); sapi_module.treat_data(PARSE_STRING, res, &tmp); } else { zval ret; /* Clear out the array that was passed in. */ zval_dtor(arrayArg); array_init(&ret); sapi_module.treat_data(PARSE_STRING, res, &ret); ZVAL_COPY_VALUE(arrayArg, &ret); } }
Exec Code
0
PHP_FUNCTION(parse_str) { char *arg; zval *arrayArg = NULL; char *res = NULL; size_t arglen; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z/", &arg, &arglen, &arrayArg) == FAILURE) { return; } res = estrndup(arg, arglen); if (arrayArg == NULL) { zval tmp; zend_array *symbol_table = zend_rebuild_symbol_table(); ZVAL_ARR(&tmp, symbol_table); sapi_module.treat_data(PARSE_STRING, res, &tmp); } else { zval ret; /* Clear out the array that was passed in. */ zval_dtor(arrayArg); array_init(&ret); sapi_module.treat_data(PARSE_STRING, res, &ret); ZVAL_COPY_VALUE(arrayArg, &ret); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,765
PHP_FUNCTION(count_chars) { zend_string *input; int chars[256]; zend_long mymode=0; unsigned char *buf; int inx; char retstr[256]; size_t retlen=0; size_t tmp = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &input, &mymode) == FAILURE) { return; } if (mymode < 0 || mymode > 4) { php_error_docref(NULL, E_WARNING, "Unknown mode"); RETURN_FALSE; } buf = (unsigned char *) ZSTR_VAL(input); memset((void*) chars, 0, sizeof(chars)); while (tmp < ZSTR_LEN(input)) { chars[*buf]++; buf++; tmp++; } if (mymode < 3) { array_init(return_value); } for (inx = 0; inx < 256; inx++) { switch (mymode) { case 0: add_index_long(return_value, inx, chars[inx]); break; case 1: if (chars[inx] != 0) { add_index_long(return_value, inx, chars[inx]); } break; case 2: if (chars[inx] == 0) { add_index_long(return_value, inx, chars[inx]); } break; case 3: if (chars[inx] != 0) { retstr[retlen++] = inx; } break; case 4: if (chars[inx] == 0) { retstr[retlen++] = inx; } break; } } if (mymode >= 3 && mymode <= 4) { RETURN_STRINGL(retstr, retlen); } }
Exec Code
0
PHP_FUNCTION(count_chars) { zend_string *input; int chars[256]; zend_long mymode=0; unsigned char *buf; int inx; char retstr[256]; size_t retlen=0; size_t tmp = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &input, &mymode) == FAILURE) { return; } if (mymode < 0 || mymode > 4) { php_error_docref(NULL, E_WARNING, "Unknown mode"); RETURN_FALSE; } buf = (unsigned char *) ZSTR_VAL(input); memset((void*) chars, 0, sizeof(chars)); while (tmp < ZSTR_LEN(input)) { chars[*buf]++; buf++; tmp++; } if (mymode < 3) { array_init(return_value); } for (inx = 0; inx < 256; inx++) { switch (mymode) { case 0: add_index_long(return_value, inx, chars[inx]); break; case 1: if (chars[inx] != 0) { add_index_long(return_value, inx, chars[inx]); } break; case 2: if (chars[inx] == 0) { add_index_long(return_value, inx, chars[inx]); } break; case 3: if (chars[inx] != 0) { retstr[retlen++] = inx; } break; case 4: if (chars[inx] == 0) { retstr[retlen++] = inx; } break; } } if (mymode >= 3 && mymode <= 4) { RETURN_STRINGL(retstr, retlen); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,766
PHP_FUNCTION(localeconv) { zval grouping, mon_grouping; int len, i; /* We don't need no stinkin' parameters... */ if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); array_init(&grouping); array_init(&mon_grouping); #ifdef HAVE_LOCALECONV { struct lconv currlocdata; localeconv_r( &currlocdata ); /* Grab the grouping data out of the array */ len = (int)strlen(currlocdata.grouping); for (i = 0; i < len; i++) { add_index_long(&grouping, i, currlocdata.grouping[i]); } /* Grab the monetary grouping data out of the array */ len = (int)strlen(currlocdata.mon_grouping); for (i = 0; i < len; i++) { add_index_long(&mon_grouping, i, currlocdata.mon_grouping[i]); } add_assoc_string(return_value, "decimal_point", currlocdata.decimal_point); add_assoc_string(return_value, "thousands_sep", currlocdata.thousands_sep); add_assoc_string(return_value, "int_curr_symbol", currlocdata.int_curr_symbol); add_assoc_string(return_value, "currency_symbol", currlocdata.currency_symbol); add_assoc_string(return_value, "mon_decimal_point", currlocdata.mon_decimal_point); add_assoc_string(return_value, "mon_thousands_sep", currlocdata.mon_thousands_sep); add_assoc_string(return_value, "positive_sign", currlocdata.positive_sign); add_assoc_string(return_value, "negative_sign", currlocdata.negative_sign); add_assoc_long( return_value, "int_frac_digits", currlocdata.int_frac_digits); add_assoc_long( return_value, "frac_digits", currlocdata.frac_digits); add_assoc_long( return_value, "p_cs_precedes", currlocdata.p_cs_precedes); add_assoc_long( return_value, "p_sep_by_space", currlocdata.p_sep_by_space); add_assoc_long( return_value, "n_cs_precedes", currlocdata.n_cs_precedes); add_assoc_long( return_value, "n_sep_by_space", currlocdata.n_sep_by_space); add_assoc_long( return_value, "p_sign_posn", currlocdata.p_sign_posn); add_assoc_long( return_value, "n_sign_posn", currlocdata.n_sign_posn); } #else /* Ok, it doesn't look like we have locale info floating around, so I guess it wouldn't hurt to just go ahead and return the POSIX locale information? */ add_index_long(&grouping, 0, -1); add_index_long(&mon_grouping, 0, -1); add_assoc_string(return_value, "decimal_point", "\x2E"); add_assoc_string(return_value, "thousands_sep", ""); add_assoc_string(return_value, "int_curr_symbol", ""); add_assoc_string(return_value, "currency_symbol", ""); add_assoc_string(return_value, "mon_decimal_point", "\x2E"); add_assoc_string(return_value, "mon_thousands_sep", ""); add_assoc_string(return_value, "positive_sign", ""); add_assoc_string(return_value, "negative_sign", ""); add_assoc_long( return_value, "int_frac_digits", CHAR_MAX); add_assoc_long( return_value, "frac_digits", CHAR_MAX); add_assoc_long( return_value, "p_cs_precedes", CHAR_MAX); add_assoc_long( return_value, "p_sep_by_space", CHAR_MAX); add_assoc_long( return_value, "n_cs_precedes", CHAR_MAX); add_assoc_long( return_value, "n_sep_by_space", CHAR_MAX); add_assoc_long( return_value, "p_sign_posn", CHAR_MAX); add_assoc_long( return_value, "n_sign_posn", CHAR_MAX); #endif zend_hash_str_update(Z_ARRVAL_P(return_value), "grouping", sizeof("grouping")-1, &grouping); zend_hash_str_update(Z_ARRVAL_P(return_value), "mon_grouping", sizeof("mon_grouping")-1, &mon_grouping); }
Exec Code
0
PHP_FUNCTION(localeconv) { zval grouping, mon_grouping; int len, i; /* We don't need no stinkin' parameters... */ if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); array_init(&grouping); array_init(&mon_grouping); #ifdef HAVE_LOCALECONV { struct lconv currlocdata; localeconv_r( &currlocdata ); /* Grab the grouping data out of the array */ len = (int)strlen(currlocdata.grouping); for (i = 0; i < len; i++) { add_index_long(&grouping, i, currlocdata.grouping[i]); } /* Grab the monetary grouping data out of the array */ len = (int)strlen(currlocdata.mon_grouping); for (i = 0; i < len; i++) { add_index_long(&mon_grouping, i, currlocdata.mon_grouping[i]); } add_assoc_string(return_value, "decimal_point", currlocdata.decimal_point); add_assoc_string(return_value, "thousands_sep", currlocdata.thousands_sep); add_assoc_string(return_value, "int_curr_symbol", currlocdata.int_curr_symbol); add_assoc_string(return_value, "currency_symbol", currlocdata.currency_symbol); add_assoc_string(return_value, "mon_decimal_point", currlocdata.mon_decimal_point); add_assoc_string(return_value, "mon_thousands_sep", currlocdata.mon_thousands_sep); add_assoc_string(return_value, "positive_sign", currlocdata.positive_sign); add_assoc_string(return_value, "negative_sign", currlocdata.negative_sign); add_assoc_long( return_value, "int_frac_digits", currlocdata.int_frac_digits); add_assoc_long( return_value, "frac_digits", currlocdata.frac_digits); add_assoc_long( return_value, "p_cs_precedes", currlocdata.p_cs_precedes); add_assoc_long( return_value, "p_sep_by_space", currlocdata.p_sep_by_space); add_assoc_long( return_value, "n_cs_precedes", currlocdata.n_cs_precedes); add_assoc_long( return_value, "n_sep_by_space", currlocdata.n_sep_by_space); add_assoc_long( return_value, "p_sign_posn", currlocdata.p_sign_posn); add_assoc_long( return_value, "n_sign_posn", currlocdata.n_sign_posn); } #else /* Ok, it doesn't look like we have locale info floating around, so I guess it wouldn't hurt to just go ahead and return the POSIX locale information? */ add_index_long(&grouping, 0, -1); add_index_long(&mon_grouping, 0, -1); add_assoc_string(return_value, "decimal_point", "\x2E"); add_assoc_string(return_value, "thousands_sep", ""); add_assoc_string(return_value, "int_curr_symbol", ""); add_assoc_string(return_value, "currency_symbol", ""); add_assoc_string(return_value, "mon_decimal_point", "\x2E"); add_assoc_string(return_value, "mon_thousands_sep", ""); add_assoc_string(return_value, "positive_sign", ""); add_assoc_string(return_value, "negative_sign", ""); add_assoc_long( return_value, "int_frac_digits", CHAR_MAX); add_assoc_long( return_value, "frac_digits", CHAR_MAX); add_assoc_long( return_value, "p_cs_precedes", CHAR_MAX); add_assoc_long( return_value, "p_sep_by_space", CHAR_MAX); add_assoc_long( return_value, "n_cs_precedes", CHAR_MAX); add_assoc_long( return_value, "n_sep_by_space", CHAR_MAX); add_assoc_long( return_value, "p_sign_posn", CHAR_MAX); add_assoc_long( return_value, "n_sign_posn", CHAR_MAX); #endif zend_hash_str_update(Z_ARRVAL_P(return_value), "grouping", sizeof("grouping")-1, &grouping); zend_hash_str_update(Z_ARRVAL_P(return_value), "mon_grouping", sizeof("mon_grouping")-1, &mon_grouping); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,767
PHP_FUNCTION(strnatcasecmp) { php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
Exec Code
0
PHP_FUNCTION(strnatcasecmp) { php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,768
PHP_FUNCTION(substr_count) { char *haystack, *needle; zend_long offset = 0, length = 0; int ac = ZEND_NUM_ARGS(); int count = 0; size_t haystack_len, needle_len; char *p, *endp, cmp; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ll", &haystack, &haystack_len, &needle, &needle_len, &offset, &length) == FAILURE) { return; } if (needle_len == 0) { php_error_docref(NULL, E_WARNING, "Empty substring"); RETURN_FALSE; } p = haystack; endp = p + haystack_len; if (offset < 0) { php_error_docref(NULL, E_WARNING, "Offset should be greater than or equal to 0"); RETURN_FALSE; } if ((size_t)offset > haystack_len) { php_error_docref(NULL, E_WARNING, "Offset value " ZEND_LONG_FMT " exceeds string length", offset); RETURN_FALSE; } p += offset; if (ac == 4) { if (length <= 0) { php_error_docref(NULL, E_WARNING, "Length should be greater than 0"); RETURN_FALSE; } if (length > (haystack_len - offset)) { php_error_docref(NULL, E_WARNING, "Length value " ZEND_LONG_FMT " exceeds string length", length); RETURN_FALSE; } endp = p + length; } if (needle_len == 1) { cmp = needle[0]; while ((p = memchr(p, cmp, endp - p))) { count++; p++; } } else { while ((p = (char*)php_memnstr(p, needle, needle_len, endp))) { p += needle_len; count++; } } RETURN_LONG(count); }
Exec Code
0
PHP_FUNCTION(substr_count) { char *haystack, *needle; zend_long offset = 0, length = 0; int ac = ZEND_NUM_ARGS(); int count = 0; size_t haystack_len, needle_len; char *p, *endp, cmp; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ll", &haystack, &haystack_len, &needle, &needle_len, &offset, &length) == FAILURE) { return; } if (needle_len == 0) { php_error_docref(NULL, E_WARNING, "Empty substring"); RETURN_FALSE; } p = haystack; endp = p + haystack_len; if (offset < 0) { php_error_docref(NULL, E_WARNING, "Offset should be greater than or equal to 0"); RETURN_FALSE; } if ((size_t)offset > haystack_len) { php_error_docref(NULL, E_WARNING, "Offset value " ZEND_LONG_FMT " exceeds string length", offset); RETURN_FALSE; } p += offset; if (ac == 4) { if (length <= 0) { php_error_docref(NULL, E_WARNING, "Length should be greater than 0"); RETURN_FALSE; } if (length > (haystack_len - offset)) { php_error_docref(NULL, E_WARNING, "Length value " ZEND_LONG_FMT " exceeds string length", length); RETURN_FALSE; } endp = p + length; } if (needle_len == 1) { cmp = needle[0]; while ((p = memchr(p, cmp, endp - p))) { count++; p++; } } else { while ((p = (char*)php_memnstr(p, needle, needle_len, endp))) { p += needle_len; count++; } } RETURN_LONG(count); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,769
PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string */ zend_long pad_length; /* Length to pad to */ /* Helper variables */ size_t num_pad_chars; /* Number of padding characters (total - input size) */ char *pad_str = " "; /* Pointer to padding string */ size_t pad_str_len = 1; zend_long pad_type_val = STR_PAD_RIGHT; /* The padding type value */ size_t i, left_pad=0, right_pad=0; zend_string *result = NULL; /* Resulting string */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|sl", &input, &pad_length, &pad_str, &pad_str_len, &pad_type_val) == FAILURE) { return; } /* If resulting string turns out to be shorter than input string, we simply copy the input and return. */ if (pad_length < 0 || (size_t)pad_length <= ZSTR_LEN(input)) { RETURN_STRINGL(ZSTR_VAL(input), ZSTR_LEN(input)); } if (pad_str_len == 0) { php_error_docref(NULL, E_WARNING, "Padding string cannot be empty"); return; } if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) { php_error_docref(NULL, E_WARNING, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH"); return; } num_pad_chars = pad_length - ZSTR_LEN(input); if (num_pad_chars >= INT_MAX) { php_error_docref(NULL, E_WARNING, "Padding length is too long"); return; } result = zend_string_alloc(ZSTR_LEN(input) + num_pad_chars, 0); ZSTR_LEN(result) = 0; /* We need to figure out the left/right padding lengths. */ switch (pad_type_val) { case STR_PAD_RIGHT: left_pad = 0; right_pad = num_pad_chars; break; case STR_PAD_LEFT: left_pad = num_pad_chars; right_pad = 0; break; case STR_PAD_BOTH: left_pad = num_pad_chars / 2; right_pad = num_pad_chars - left_pad; break; } /* First we pad on the left. */ for (i = 0; i < left_pad; i++) ZSTR_VAL(result)[ZSTR_LEN(result)++] = pad_str[i % pad_str_len]; /* Then we copy the input string. */ memcpy(ZSTR_VAL(result) + ZSTR_LEN(result), ZSTR_VAL(input), ZSTR_LEN(input)); ZSTR_LEN(result) += ZSTR_LEN(input); /* Finally, we pad on the right. */ for (i = 0; i < right_pad; i++) ZSTR_VAL(result)[ZSTR_LEN(result)++] = pad_str[i % pad_str_len]; ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); }
Exec Code
0
PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string */ zend_long pad_length; /* Length to pad to */ /* Helper variables */ size_t num_pad_chars; /* Number of padding characters (total - input size) */ char *pad_str = " "; /* Pointer to padding string */ size_t pad_str_len = 1; zend_long pad_type_val = STR_PAD_RIGHT; /* The padding type value */ size_t i, left_pad=0, right_pad=0; zend_string *result = NULL; /* Resulting string */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|sl", &input, &pad_length, &pad_str, &pad_str_len, &pad_type_val) == FAILURE) { return; } /* If resulting string turns out to be shorter than input string, we simply copy the input and return. */ if (pad_length < 0 || (size_t)pad_length <= ZSTR_LEN(input)) { RETURN_STRINGL(ZSTR_VAL(input), ZSTR_LEN(input)); } if (pad_str_len == 0) { php_error_docref(NULL, E_WARNING, "Padding string cannot be empty"); return; } if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) { php_error_docref(NULL, E_WARNING, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH"); return; } num_pad_chars = pad_length - ZSTR_LEN(input); if (num_pad_chars >= INT_MAX) { php_error_docref(NULL, E_WARNING, "Padding length is too long"); return; } result = zend_string_alloc(ZSTR_LEN(input) + num_pad_chars, 0); ZSTR_LEN(result) = 0; /* We need to figure out the left/right padding lengths. */ switch (pad_type_val) { case STR_PAD_RIGHT: left_pad = 0; right_pad = num_pad_chars; break; case STR_PAD_LEFT: left_pad = num_pad_chars; right_pad = 0; break; case STR_PAD_BOTH: left_pad = num_pad_chars / 2; right_pad = num_pad_chars - left_pad; break; } /* First we pad on the left. */ for (i = 0; i < left_pad; i++) ZSTR_VAL(result)[ZSTR_LEN(result)++] = pad_str[i % pad_str_len]; /* Then we copy the input string. */ memcpy(ZSTR_VAL(result) + ZSTR_LEN(result), ZSTR_VAL(input), ZSTR_LEN(input)); ZSTR_LEN(result) += ZSTR_LEN(input); /* Finally, we pad on the right. */ for (i = 0; i < right_pad; i++) ZSTR_VAL(result)[ZSTR_LEN(result)++] = pad_str[i % pad_str_len]; ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; RETURN_NEW_STR(result); }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,770
PHP_FUNCTION(sscanf) { zval *args = NULL; char *str, *format; size_t str_len, format_len; int result, num_args = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss*", &str, &str_len, &format, &format_len, &args, &num_args) == FAILURE) { return; } result = php_sscanf_internal(str, format, num_args, args, 0, return_value); if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { WRONG_PARAM_COUNT; } }
Exec Code
0
PHP_FUNCTION(sscanf) { zval *args = NULL; char *str, *format; size_t str_len, format_len; int result, num_args = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss*", &str, &str_len, &format, &format_len, &args, &num_args) == FAILURE) { return; } result = php_sscanf_internal(str, format, num_args, args, 0, return_value); if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { WRONG_PARAM_COUNT; } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,771
PHP_FUNCTION(str_rot13) { zend_string *arg; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &arg) == FAILURE) { return; } if (ZSTR_LEN(arg) == 0) { RETURN_EMPTY_STRING(); } else { RETURN_STR(php_strtr_ex(arg, rot13_from, rot13_to, 52)); } }
Exec Code
0
PHP_FUNCTION(str_rot13) { zend_string *arg; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &arg) == FAILURE) { return; } if (ZSTR_LEN(arg) == 0) { RETURN_EMPTY_STRING(); } else { RETURN_STR(php_strtr_ex(arg, rot13_from, rot13_to, 52)); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,772
PHP_FUNCTION(str_word_count) { zend_string *str; char *char_list = NULL, *p, *e, *s, ch[256]; size_t char_list_len = 0, word_count = 0; zend_long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls", &str, &type, &char_list, &char_list_len) == FAILURE) { return; } switch(type) { case 1: case 2: array_init(return_value); if (!ZSTR_LEN(str)) { return; } break; case 0: if (!ZSTR_LEN(str)) { RETURN_LONG(0); } /* nothing to be done */ break; default: php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); RETURN_FALSE; } if (char_list) { php_charmask((unsigned char *)char_list, char_list_len, ch); } p = ZSTR_VAL(str); e = ZSTR_VAL(str) + ZSTR_LEN(str); /* first character cannot be ' or -, unless explicitly allowed by the user */ if ((*p == '\'' && (!char_list || !ch['\''])) || (*p == '-' && (!char_list || !ch['-']))) { p++; } /* last character cannot be -, unless explicitly allowed by the user */ if (*(e - 1) == '-' && (!char_list || !ch['-'])) { e--; } while (p < e) { s = p; while (p < e && (isalpha((unsigned char)*p) || (char_list && ch[(unsigned char)*p]) || *p == '\'' || *p == '-')) { p++; } if (p > s) { switch (type) { case 1: add_next_index_stringl(return_value, s, p - s); break; case 2: add_index_stringl(return_value, (s - ZSTR_VAL(str)), s, p - s); break; default: word_count++; break; } } p++; } if (!type) { RETURN_LONG(word_count); } }
Exec Code
0
PHP_FUNCTION(str_word_count) { zend_string *str; char *char_list = NULL, *p, *e, *s, ch[256]; size_t char_list_len = 0, word_count = 0; zend_long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls", &str, &type, &char_list, &char_list_len) == FAILURE) { return; } switch(type) { case 1: case 2: array_init(return_value); if (!ZSTR_LEN(str)) { return; } break; case 0: if (!ZSTR_LEN(str)) { RETURN_LONG(0); } /* nothing to be done */ break; default: php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); RETURN_FALSE; } if (char_list) { php_charmask((unsigned char *)char_list, char_list_len, ch); } p = ZSTR_VAL(str); e = ZSTR_VAL(str) + ZSTR_LEN(str); /* first character cannot be ' or -, unless explicitly allowed by the user */ if ((*p == '\'' && (!char_list || !ch['\''])) || (*p == '-' && (!char_list || !ch['-']))) { p++; } /* last character cannot be -, unless explicitly allowed by the user */ if (*(e - 1) == '-' && (!char_list || !ch['-'])) { e--; } while (p < e) { s = p; while (p < e && (isalpha((unsigned char)*p) || (char_list && ch[(unsigned char)*p]) || *p == '\'' || *p == '-')) { p++; } if (p > s) { switch (type) { case 1: add_next_index_stringl(return_value, s, p - s); break; case 2: add_index_stringl(return_value, (s - ZSTR_VAL(str)), s, p - s); break; default: word_count++; break; } } p++; } if (!type) { RETURN_LONG(word_count); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,773
PHP_FUNCTION(str_split) { zend_string *str; zend_long split_length = 1; char *p; size_t n_reg_segments; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &str, &split_length) == FAILURE) { return; } if (split_length <= 0) { php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero"); RETURN_FALSE; } if (0 == ZSTR_LEN(str) || (size_t)split_length >= ZSTR_LEN(str)) { array_init_size(return_value, 1); add_next_index_stringl(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); return; } array_init_size(return_value, (uint32_t)(((ZSTR_LEN(str) - 1) / split_length) + 1)); n_reg_segments = ZSTR_LEN(str) / split_length; p = ZSTR_VAL(str); while (n_reg_segments-- > 0) { add_next_index_stringl(return_value, p, split_length); p += split_length; } if (p != (ZSTR_VAL(str) + ZSTR_LEN(str))) { add_next_index_stringl(return_value, p, (ZSTR_VAL(str) + ZSTR_LEN(str) - p)); } }
Exec Code
0
PHP_FUNCTION(str_split) { zend_string *str; zend_long split_length = 1; char *p; size_t n_reg_segments; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &str, &split_length) == FAILURE) { return; } if (split_length <= 0) { php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero"); RETURN_FALSE; } if (0 == ZSTR_LEN(str) || (size_t)split_length >= ZSTR_LEN(str)) { array_init_size(return_value, 1); add_next_index_stringl(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); return; } array_init_size(return_value, (uint32_t)(((ZSTR_LEN(str) - 1) / split_length) + 1)); n_reg_segments = ZSTR_LEN(str) / split_length; p = ZSTR_VAL(str); while (n_reg_segments-- > 0) { add_next_index_stringl(return_value, p, split_length); p += split_length; } if (p != (ZSTR_VAL(str) + ZSTR_LEN(str))) { add_next_index_stringl(return_value, p, (ZSTR_VAL(str) + ZSTR_LEN(str) - p)); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,774
PHP_FUNCTION(strpbrk) { zend_string *haystack, *char_list; char *haystack_ptr, *cl_ptr; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &haystack, &char_list) == FAILURE) { RETURN_FALSE; } if (!ZSTR_LEN(char_list)) { php_error_docref(NULL, E_WARNING, "The character list cannot be empty"); RETURN_FALSE; } for (haystack_ptr = ZSTR_VAL(haystack); haystack_ptr < (ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); ++haystack_ptr) { for (cl_ptr = ZSTR_VAL(char_list); cl_ptr < (ZSTR_VAL(char_list) + ZSTR_LEN(char_list)); ++cl_ptr) { if (*cl_ptr == *haystack_ptr) { RETURN_STRINGL(haystack_ptr, (ZSTR_VAL(haystack) + ZSTR_LEN(haystack) - haystack_ptr)); } } } RETURN_FALSE; }
Exec Code
0
PHP_FUNCTION(strpbrk) { zend_string *haystack, *char_list; char *haystack_ptr, *cl_ptr; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &haystack, &char_list) == FAILURE) { RETURN_FALSE; } if (!ZSTR_LEN(char_list)) { php_error_docref(NULL, E_WARNING, "The character list cannot be empty"); RETURN_FALSE; } for (haystack_ptr = ZSTR_VAL(haystack); haystack_ptr < (ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); ++haystack_ptr) { for (cl_ptr = ZSTR_VAL(char_list); cl_ptr < (ZSTR_VAL(char_list) + ZSTR_LEN(char_list)); ++cl_ptr) { if (*cl_ptr == *haystack_ptr) { RETURN_STRINGL(haystack_ptr, (ZSTR_VAL(haystack) + ZSTR_LEN(haystack) - haystack_ptr)); } } } RETURN_FALSE; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,775
PHP_FUNCTION(substr_compare) { zend_string *s1, *s2; zend_long offset, len=0; zend_bool cs=0; size_t cmp_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|lb", &s1, &s2, &offset, &len, &cs) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() >= 4 && len <= 0) { if (len == 0) { RETURN_LONG(0L); } else { php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero"); RETURN_FALSE; } } if (offset < 0) { offset = ZSTR_LEN(s1) + offset; offset = (offset < 0) ? 0 : offset; } if ((size_t)offset >= ZSTR_LEN(s1)) { php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } cmp_len = (size_t) (len ? len : MAX(ZSTR_LEN(s2), (ZSTR_LEN(s1) - offset))); if (!cs) { RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1) + offset, (ZSTR_LEN(s1) - offset), ZSTR_VAL(s2), ZSTR_LEN(s2), cmp_len)); } else { RETURN_LONG(zend_binary_strncasecmp_l(ZSTR_VAL(s1) + offset, (ZSTR_LEN(s1) - offset), ZSTR_VAL(s2), ZSTR_LEN(s2), cmp_len)); } }
Exec Code
0
PHP_FUNCTION(substr_compare) { zend_string *s1, *s2; zend_long offset, len=0; zend_bool cs=0; size_t cmp_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|lb", &s1, &s2, &offset, &len, &cs) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() >= 4 && len <= 0) { if (len == 0) { RETURN_LONG(0L); } else { php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero"); RETURN_FALSE; } } if (offset < 0) { offset = ZSTR_LEN(s1) + offset; offset = (offset < 0) ? 0 : offset; } if ((size_t)offset >= ZSTR_LEN(s1)) { php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } cmp_len = (size_t) (len ? len : MAX(ZSTR_LEN(s2), (ZSTR_LEN(s1) - offset))); if (!cs) { RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1) + offset, (ZSTR_LEN(s1) - offset), ZSTR_VAL(s2), ZSTR_LEN(s2), cmp_len)); } else { RETURN_LONG(zend_binary_strncasecmp_l(ZSTR_VAL(s1) + offset, (ZSTR_LEN(s1) - offset), ZSTR_VAL(s2), ZSTR_LEN(s2), cmp_len)); } }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,776
PHP_MINIT_FUNCTION(localeconv) { locale_mutex = tsrm_mutex_alloc(); return SUCCESS; }
Exec Code
0
PHP_MINIT_FUNCTION(localeconv) { locale_mutex = tsrm_mutex_alloc(); return SUCCESS; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,777
PHP_MINIT_FUNCTION(nl_langinfo) { #define REGISTER_NL_LANGINFO_CONSTANT(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT) #ifdef ABDAY_1 REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7); #endif #ifdef DAY_1 REGISTER_NL_LANGINFO_CONSTANT(DAY_1); REGISTER_NL_LANGINFO_CONSTANT(DAY_2); REGISTER_NL_LANGINFO_CONSTANT(DAY_3); REGISTER_NL_LANGINFO_CONSTANT(DAY_4); REGISTER_NL_LANGINFO_CONSTANT(DAY_5); REGISTER_NL_LANGINFO_CONSTANT(DAY_6); REGISTER_NL_LANGINFO_CONSTANT(DAY_7); #endif #ifdef ABMON_1 REGISTER_NL_LANGINFO_CONSTANT(ABMON_1); REGISTER_NL_LANGINFO_CONSTANT(ABMON_2); REGISTER_NL_LANGINFO_CONSTANT(ABMON_3); REGISTER_NL_LANGINFO_CONSTANT(ABMON_4); REGISTER_NL_LANGINFO_CONSTANT(ABMON_5); REGISTER_NL_LANGINFO_CONSTANT(ABMON_6); REGISTER_NL_LANGINFO_CONSTANT(ABMON_7); REGISTER_NL_LANGINFO_CONSTANT(ABMON_8); REGISTER_NL_LANGINFO_CONSTANT(ABMON_9); REGISTER_NL_LANGINFO_CONSTANT(ABMON_10); REGISTER_NL_LANGINFO_CONSTANT(ABMON_11); REGISTER_NL_LANGINFO_CONSTANT(ABMON_12); #endif #ifdef MON_1 REGISTER_NL_LANGINFO_CONSTANT(MON_1); REGISTER_NL_LANGINFO_CONSTANT(MON_2); REGISTER_NL_LANGINFO_CONSTANT(MON_3); REGISTER_NL_LANGINFO_CONSTANT(MON_4); REGISTER_NL_LANGINFO_CONSTANT(MON_5); REGISTER_NL_LANGINFO_CONSTANT(MON_6); REGISTER_NL_LANGINFO_CONSTANT(MON_7); REGISTER_NL_LANGINFO_CONSTANT(MON_8); REGISTER_NL_LANGINFO_CONSTANT(MON_9); REGISTER_NL_LANGINFO_CONSTANT(MON_10); REGISTER_NL_LANGINFO_CONSTANT(MON_11); REGISTER_NL_LANGINFO_CONSTANT(MON_12); #endif #ifdef AM_STR REGISTER_NL_LANGINFO_CONSTANT(AM_STR); #endif #ifdef PM_STR REGISTER_NL_LANGINFO_CONSTANT(PM_STR); #endif #ifdef D_T_FMT REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT); #endif #ifdef D_FMT REGISTER_NL_LANGINFO_CONSTANT(D_FMT); #endif #ifdef T_FMT REGISTER_NL_LANGINFO_CONSTANT(T_FMT); #endif #ifdef T_FMT_AMPM REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM); #endif #ifdef ERA REGISTER_NL_LANGINFO_CONSTANT(ERA); #endif #ifdef ERA_YEAR REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR); #endif #ifdef ERA_D_T_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT); #endif #ifdef ERA_D_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT); #endif #ifdef ERA_T_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT); #endif #ifdef ALT_DIGITS REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS); #endif #ifdef INT_CURR_SYMBOL REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL); #endif #ifdef CURRENCY_SYMBOL REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL); #endif #ifdef CRNCYSTR REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR); #endif #ifdef MON_DECIMAL_POINT REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT); #endif #ifdef MON_THOUSANDS_SEP REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP); #endif #ifdef MON_GROUPING REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING); #endif #ifdef POSITIVE_SIGN REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN); #endif #ifdef NEGATIVE_SIGN REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN); #endif #ifdef INT_FRAC_DIGITS REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS); #endif #ifdef FRAC_DIGITS REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS); #endif #ifdef P_CS_PRECEDES REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES); #endif #ifdef P_SEP_BY_SPACE REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE); #endif #ifdef N_CS_PRECEDES REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES); #endif #ifdef N_SEP_BY_SPACE REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE); #endif #ifdef P_SIGN_POSN REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN); #endif #ifdef N_SIGN_POSN REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN); #endif #ifdef DECIMAL_POINT REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT); #endif #ifdef RADIXCHAR REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR); #endif #ifdef THOUSANDS_SEP REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP); #endif #ifdef THOUSEP REGISTER_NL_LANGINFO_CONSTANT(THOUSEP); #endif #ifdef GROUPING REGISTER_NL_LANGINFO_CONSTANT(GROUPING); #endif #ifdef YESEXPR REGISTER_NL_LANGINFO_CONSTANT(YESEXPR); #endif #ifdef NOEXPR REGISTER_NL_LANGINFO_CONSTANT(NOEXPR); #endif #ifdef YESSTR REGISTER_NL_LANGINFO_CONSTANT(YESSTR); #endif #ifdef NOSTR REGISTER_NL_LANGINFO_CONSTANT(NOSTR); #endif #ifdef CODESET REGISTER_NL_LANGINFO_CONSTANT(CODESET); #endif #undef REGISTER_NL_LANGINFO_CONSTANT return SUCCESS; }
Exec Code
0
PHP_MINIT_FUNCTION(nl_langinfo) { #define REGISTER_NL_LANGINFO_CONSTANT(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT) #ifdef ABDAY_1 REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6); REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7); #endif #ifdef DAY_1 REGISTER_NL_LANGINFO_CONSTANT(DAY_1); REGISTER_NL_LANGINFO_CONSTANT(DAY_2); REGISTER_NL_LANGINFO_CONSTANT(DAY_3); REGISTER_NL_LANGINFO_CONSTANT(DAY_4); REGISTER_NL_LANGINFO_CONSTANT(DAY_5); REGISTER_NL_LANGINFO_CONSTANT(DAY_6); REGISTER_NL_LANGINFO_CONSTANT(DAY_7); #endif #ifdef ABMON_1 REGISTER_NL_LANGINFO_CONSTANT(ABMON_1); REGISTER_NL_LANGINFO_CONSTANT(ABMON_2); REGISTER_NL_LANGINFO_CONSTANT(ABMON_3); REGISTER_NL_LANGINFO_CONSTANT(ABMON_4); REGISTER_NL_LANGINFO_CONSTANT(ABMON_5); REGISTER_NL_LANGINFO_CONSTANT(ABMON_6); REGISTER_NL_LANGINFO_CONSTANT(ABMON_7); REGISTER_NL_LANGINFO_CONSTANT(ABMON_8); REGISTER_NL_LANGINFO_CONSTANT(ABMON_9); REGISTER_NL_LANGINFO_CONSTANT(ABMON_10); REGISTER_NL_LANGINFO_CONSTANT(ABMON_11); REGISTER_NL_LANGINFO_CONSTANT(ABMON_12); #endif #ifdef MON_1 REGISTER_NL_LANGINFO_CONSTANT(MON_1); REGISTER_NL_LANGINFO_CONSTANT(MON_2); REGISTER_NL_LANGINFO_CONSTANT(MON_3); REGISTER_NL_LANGINFO_CONSTANT(MON_4); REGISTER_NL_LANGINFO_CONSTANT(MON_5); REGISTER_NL_LANGINFO_CONSTANT(MON_6); REGISTER_NL_LANGINFO_CONSTANT(MON_7); REGISTER_NL_LANGINFO_CONSTANT(MON_8); REGISTER_NL_LANGINFO_CONSTANT(MON_9); REGISTER_NL_LANGINFO_CONSTANT(MON_10); REGISTER_NL_LANGINFO_CONSTANT(MON_11); REGISTER_NL_LANGINFO_CONSTANT(MON_12); #endif #ifdef AM_STR REGISTER_NL_LANGINFO_CONSTANT(AM_STR); #endif #ifdef PM_STR REGISTER_NL_LANGINFO_CONSTANT(PM_STR); #endif #ifdef D_T_FMT REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT); #endif #ifdef D_FMT REGISTER_NL_LANGINFO_CONSTANT(D_FMT); #endif #ifdef T_FMT REGISTER_NL_LANGINFO_CONSTANT(T_FMT); #endif #ifdef T_FMT_AMPM REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM); #endif #ifdef ERA REGISTER_NL_LANGINFO_CONSTANT(ERA); #endif #ifdef ERA_YEAR REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR); #endif #ifdef ERA_D_T_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT); #endif #ifdef ERA_D_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT); #endif #ifdef ERA_T_FMT REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT); #endif #ifdef ALT_DIGITS REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS); #endif #ifdef INT_CURR_SYMBOL REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL); #endif #ifdef CURRENCY_SYMBOL REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL); #endif #ifdef CRNCYSTR REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR); #endif #ifdef MON_DECIMAL_POINT REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT); #endif #ifdef MON_THOUSANDS_SEP REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP); #endif #ifdef MON_GROUPING REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING); #endif #ifdef POSITIVE_SIGN REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN); #endif #ifdef NEGATIVE_SIGN REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN); #endif #ifdef INT_FRAC_DIGITS REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS); #endif #ifdef FRAC_DIGITS REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS); #endif #ifdef P_CS_PRECEDES REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES); #endif #ifdef P_SEP_BY_SPACE REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE); #endif #ifdef N_CS_PRECEDES REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES); #endif #ifdef N_SEP_BY_SPACE REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE); #endif #ifdef P_SIGN_POSN REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN); #endif #ifdef N_SIGN_POSN REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN); #endif #ifdef DECIMAL_POINT REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT); #endif #ifdef RADIXCHAR REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR); #endif #ifdef THOUSANDS_SEP REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP); #endif #ifdef THOUSEP REGISTER_NL_LANGINFO_CONSTANT(THOUSEP); #endif #ifdef GROUPING REGISTER_NL_LANGINFO_CONSTANT(GROUPING); #endif #ifdef YESEXPR REGISTER_NL_LANGINFO_CONSTANT(YESEXPR); #endif #ifdef NOEXPR REGISTER_NL_LANGINFO_CONSTANT(NOEXPR); #endif #ifdef YESSTR REGISTER_NL_LANGINFO_CONSTANT(YESSTR); #endif #ifdef NOSTR REGISTER_NL_LANGINFO_CONSTANT(NOSTR); #endif #ifdef CODESET REGISTER_NL_LANGINFO_CONSTANT(CODESET); #endif #undef REGISTER_NL_LANGINFO_CONSTANT return SUCCESS; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,778
PHP_MSHUTDOWN_FUNCTION(localeconv) { tsrm_mutex_free( locale_mutex ); locale_mutex = NULL; return SUCCESS; }
Exec Code
0
PHP_MSHUTDOWN_FUNCTION(localeconv) { tsrm_mutex_free( locale_mutex ); locale_mutex = NULL; return SUCCESS; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,779
PHPAPI struct lconv *localeconv_r(struct lconv *out) { struct lconv *res; # ifdef ZTS tsrm_mutex_lock( locale_mutex ); # endif /* cur->locinfo is struct __crt_locale_info which implementation is hidden in vc14. TODO revisit this and check if a workaround available and needed. */ #if defined(PHP_WIN32) && _MSC_VER < 1900 && defined(ZTS) { /* Even with the enabled per thread locale, localeconv won't check any locale change in the master thread. */ _locale_t cur = _get_current_locale(); res = cur->locinfo->lconv; } #else /* localeconv doesn't return an error condition */ res = localeconv(); #endif *out = *res; # ifdef ZTS tsrm_mutex_unlock( locale_mutex ); # endif return out; }
Exec Code
0
PHPAPI struct lconv *localeconv_r(struct lconv *out) { struct lconv *res; # ifdef ZTS tsrm_mutex_lock( locale_mutex ); # endif /* cur->locinfo is struct __crt_locale_info which implementation is hidden in vc14. TODO revisit this and check if a workaround available and needed. */ #if defined(PHP_WIN32) && _MSC_VER < 1900 && defined(ZTS) { /* Even with the enabled per thread locale, localeconv won't check any locale change in the master thread. */ _locale_t cur = _get_current_locale(); res = cur->locinfo->lconv; } #else /* localeconv doesn't return an error condition */ res = localeconv(); #endif *out = *res; # ifdef ZTS tsrm_mutex_unlock( locale_mutex ); # endif return out; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,780
PHPAPI zend_string *php_addcslashes(zend_string *str, int should_free, char *what, size_t wlength) { char flags[256]; char *source, *target; char *end; char c; size_t newlen; zend_string *new_str = zend_string_alloc(4 * ZSTR_LEN(str), 0); php_charmask((unsigned char *)what, wlength, flags); for (source = (char*)ZSTR_VAL(str), end = source + ZSTR_LEN(str), target = ZSTR_VAL(new_str); source < end; source++) { c = *source; if (flags[(unsigned char)c]) { if ((unsigned char) c < 32 || (unsigned char) c > 126) { *target++ = '\\'; switch (c) { case '\n': *target++ = 'n'; break; case '\t': *target++ = 't'; break; case '\r': *target++ = 'r'; break; case '\a': *target++ = 'a'; break; case '\v': *target++ = 'v'; break; case '\b': *target++ = 'b'; break; case '\f': *target++ = 'f'; break; default: target += sprintf(target, "%03o", (unsigned char) c); } continue; } *target++ = '\\'; } *target++ = c; } *target = 0; newlen = target - ZSTR_VAL(new_str); if (newlen < ZSTR_LEN(str) * 4) { new_str = zend_string_truncate(new_str, newlen, 0); } if (should_free) { zend_string_release(str); } return new_str; }
Exec Code
0
PHPAPI zend_string *php_addcslashes(zend_string *str, int should_free, char *what, size_t wlength) { char flags[256]; char *source, *target; char *end; char c; size_t newlen; zend_string *new_str = zend_string_alloc(4 * ZSTR_LEN(str), 0); php_charmask((unsigned char *)what, wlength, flags); for (source = (char*)ZSTR_VAL(str), end = source + ZSTR_LEN(str), target = ZSTR_VAL(new_str); source < end; source++) { c = *source; if (flags[(unsigned char)c]) { if ((unsigned char) c < 32 || (unsigned char) c > 126) { *target++ = '\\'; switch (c) { case '\n': *target++ = 'n'; break; case '\t': *target++ = 't'; break; case '\r': *target++ = 'r'; break; case '\a': *target++ = 'a'; break; case '\v': *target++ = 'v'; break; case '\b': *target++ = 'b'; break; case '\f': *target++ = 'f'; break; default: target += sprintf(target, "%03o", (unsigned char) c); } continue; } *target++ = '\\'; } *target++ = c; } *target = 0; newlen = target - ZSTR_VAL(new_str); if (newlen < ZSTR_LEN(str) * 4) { new_str = zend_string_truncate(new_str, newlen, 0); } if (should_free) { zend_string_release(str); } return new_str; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,781
PHPAPI zend_string *php_addslashes(zend_string *str, int should_free) { /* maximum string length, worst case situation */ char *source, *target; char *end; size_t offset; zend_string *new_str; if (!str) { return ZSTR_EMPTY_ALLOC(); } source = ZSTR_VAL(str); end = source + ZSTR_LEN(str); while (source < end) { switch (*source) { case '\0': case '\'': case '\"': case '\\': goto do_escape; default: source++; break; } } if (!should_free) { return zend_string_copy(str); } return str; do_escape: offset = source - (char *)ZSTR_VAL(str); new_str = zend_string_alloc(offset + (2 * (ZSTR_LEN(str) - offset)), 0); memcpy(ZSTR_VAL(new_str), ZSTR_VAL(str), offset); target = ZSTR_VAL(new_str) + offset; while (source < end) { switch (*source) { case '\0': *target++ = '\\'; *target++ = '0'; break; case '\'': case '\"': case '\\': *target++ = '\\'; /* break is missing *intentionally* */ default: *target++ = *source; break; } source++; } *target = 0; if (should_free) { zend_string_release(str); } if (ZSTR_LEN(new_str) - (target - ZSTR_VAL(new_str)) > 16) { new_str = zend_string_truncate(new_str, target - ZSTR_VAL(new_str), 0); } else { ZSTR_LEN(new_str) = target - ZSTR_VAL(new_str); } return new_str; }
Exec Code
0
PHPAPI zend_string *php_addslashes(zend_string *str, int should_free) { /* maximum string length, worst case situation */ char *source, *target; char *end; size_t offset; zend_string *new_str; if (!str) { return ZSTR_EMPTY_ALLOC(); } source = ZSTR_VAL(str); end = source + ZSTR_LEN(str); while (source < end) { switch (*source) { case '\0': case '\'': case '\"': case '\\': goto do_escape; default: source++; break; } } if (!should_free) { return zend_string_copy(str); } return str; do_escape: offset = source - (char *)ZSTR_VAL(str); new_str = zend_string_alloc(offset + (2 * (ZSTR_LEN(str) - offset)), 0); memcpy(ZSTR_VAL(new_str), ZSTR_VAL(str), offset); target = ZSTR_VAL(new_str) + offset; while (source < end) { switch (*source) { case '\0': *target++ = '\\'; *target++ = '0'; break; case '\'': case '\"': case '\\': *target++ = '\\'; /* break is missing *intentionally* */ default: *target++ = *source; break; } source++; } *target = 0; if (should_free) { zend_string_release(str); } if (ZSTR_LEN(new_str) - (target - ZSTR_VAL(new_str)) > 16) { new_str = zend_string_truncate(new_str, target - ZSTR_VAL(new_str), 0); } else { ZSTR_LEN(new_str) = target - ZSTR_VAL(new_str); } return new_str; }
@@ -4055,7 +4055,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s Z_STRVAL_P(search), Z_STRLEN_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); } else { - lc_subject_str = php_string_tolower(Z_STR_P(subject)); + lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), Z_STR_P(search), Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count));
CWE-17
null
null
11,782
int phar_detect_phar_fname_ext(const char *filename, int filename_len, const char **ext_str, int *ext_len, int executable, int for_create, int is_complete TSRMLS_DC) /* {{{ */ { const char *pos, *slash; *ext_str = NULL; *ext_len = 0; if (!filename_len || filename_len == 1) { return FAILURE; } phar_request_initialize(TSRMLS_C); /* first check for alias in first segment */ pos = memchr(filename, '/', filename_len); if (pos && pos != filename) { /* check for url like http:// or phar:// */ if (*(pos - 1) == ':' && (pos - filename) < filename_len - 1 && *(pos + 1) == '/') { *ext_len = -2; *ext_str = NULL; return FAILURE; } if (zend_hash_exists(&(PHAR_GLOBALS->phar_alias_map), (char *) filename, pos - filename)) { *ext_str = pos; *ext_len = -1; return FAILURE; } if (PHAR_G(manifest_cached) && zend_hash_exists(&cached_alias, (char *) filename, pos - filename)) { *ext_str = pos; *ext_len = -1; return FAILURE; } } if (zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)) || PHAR_G(manifest_cached)) { phar_archive_data **pphar; if (is_complete) { if (SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), (char *) filename, filename_len, (void **)&pphar)) { *ext_str = filename + (filename_len - (*pphar)->ext_len); woohoo: *ext_len = (*pphar)->ext_len; if (executable == 2) { return SUCCESS; } if (executable == 1 && !(*pphar)->is_data) { return SUCCESS; } if (!executable && (*pphar)->is_data) { return SUCCESS; } return FAILURE; } if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_find(&cached_phars, (char *) filename, filename_len, (void **)&pphar)) { *ext_str = filename + (filename_len - (*pphar)->ext_len); goto woohoo; } } else { phar_zstr key; char *str_key; uint keylen; ulong unused; zend_hash_internal_pointer_reset(&(PHAR_GLOBALS->phar_fname_map)); while (FAILURE != zend_hash_has_more_elements(&(PHAR_GLOBALS->phar_fname_map))) { if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&(PHAR_GLOBALS->phar_fname_map), &key, &keylen, &unused, 0, NULL)) { break; } PHAR_STR(key, str_key); if (keylen > (uint) filename_len) { zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map)); PHAR_STR_FREE(str_key); continue; } if (!memcmp(filename, str_key, keylen) && ((uint)filename_len == keylen || filename[keylen] == '/' || filename[keylen] == '\0')) { PHAR_STR_FREE(str_key); if (FAILURE == zend_hash_get_current_data(&(PHAR_GLOBALS->phar_fname_map), (void **) &pphar)) { break; } *ext_str = filename + (keylen - (*pphar)->ext_len); goto woohoo; } PHAR_STR_FREE(str_key); zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map)); } if (PHAR_G(manifest_cached)) { zend_hash_internal_pointer_reset(&cached_phars); while (FAILURE != zend_hash_has_more_elements(&cached_phars)) { if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&cached_phars, &key, &keylen, &unused, 0, NULL)) { break; } PHAR_STR(key, str_key); if (keylen > (uint) filename_len) { zend_hash_move_forward(&cached_phars); PHAR_STR_FREE(str_key); continue; } if (!memcmp(filename, str_key, keylen) && ((uint)filename_len == keylen || filename[keylen] == '/' || filename[keylen] == '\0')) { PHAR_STR_FREE(str_key); if (FAILURE == zend_hash_get_current_data(&cached_phars, (void **) &pphar)) { break; } *ext_str = filename + (keylen - (*pphar)->ext_len); goto woohoo; } PHAR_STR_FREE(str_key); zend_hash_move_forward(&cached_phars); } } } } pos = memchr(filename + 1, '.', filename_len); next_extension: if (!pos) { return FAILURE; } while (pos != filename && (*(pos - 1) == '/' || *(pos - 1) == '\0')) { pos = memchr(pos + 1, '.', filename_len - (pos - filename) + 1); if (!pos) { return FAILURE; } } slash = memchr(pos, '/', filename_len - (pos - filename)); if (!slash) { /* this is a url like "phar://blah.phar" with no directory */ *ext_str = pos; *ext_len = strlen(pos); /* file extension must contain "phar" */ switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create TSRMLS_CC)) { case SUCCESS: return SUCCESS; case FAILURE: /* we are at the end of the string, so we fail */ return FAILURE; } } /* we've found an extension that ends at a directory separator */ *ext_str = pos; *ext_len = slash - pos; switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create TSRMLS_CC)) { case SUCCESS: return SUCCESS; case FAILURE: /* look for more extensions */ pos = strchr(pos + 1, '.'); if (pos) { *ext_str = NULL; *ext_len = 0; } goto next_extension; } return FAILURE; } /* }}} */
DoS Overflow
0
int phar_detect_phar_fname_ext(const char *filename, int filename_len, const char **ext_str, int *ext_len, int executable, int for_create, int is_complete TSRMLS_DC) /* {{{ */ { const char *pos, *slash; *ext_str = NULL; *ext_len = 0; if (!filename_len || filename_len == 1) { return FAILURE; } phar_request_initialize(TSRMLS_C); /* first check for alias in first segment */ pos = memchr(filename, '/', filename_len); if (pos && pos != filename) { /* check for url like http:// or phar:// */ if (*(pos - 1) == ':' && (pos - filename) < filename_len - 1 && *(pos + 1) == '/') { *ext_len = -2; *ext_str = NULL; return FAILURE; } if (zend_hash_exists(&(PHAR_GLOBALS->phar_alias_map), (char *) filename, pos - filename)) { *ext_str = pos; *ext_len = -1; return FAILURE; } if (PHAR_G(manifest_cached) && zend_hash_exists(&cached_alias, (char *) filename, pos - filename)) { *ext_str = pos; *ext_len = -1; return FAILURE; } } if (zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)) || PHAR_G(manifest_cached)) { phar_archive_data **pphar; if (is_complete) { if (SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), (char *) filename, filename_len, (void **)&pphar)) { *ext_str = filename + (filename_len - (*pphar)->ext_len); woohoo: *ext_len = (*pphar)->ext_len; if (executable == 2) { return SUCCESS; } if (executable == 1 && !(*pphar)->is_data) { return SUCCESS; } if (!executable && (*pphar)->is_data) { return SUCCESS; } return FAILURE; } if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_find(&cached_phars, (char *) filename, filename_len, (void **)&pphar)) { *ext_str = filename + (filename_len - (*pphar)->ext_len); goto woohoo; } } else { phar_zstr key; char *str_key; uint keylen; ulong unused; zend_hash_internal_pointer_reset(&(PHAR_GLOBALS->phar_fname_map)); while (FAILURE != zend_hash_has_more_elements(&(PHAR_GLOBALS->phar_fname_map))) { if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&(PHAR_GLOBALS->phar_fname_map), &key, &keylen, &unused, 0, NULL)) { break; } PHAR_STR(key, str_key); if (keylen > (uint) filename_len) { zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map)); PHAR_STR_FREE(str_key); continue; } if (!memcmp(filename, str_key, keylen) && ((uint)filename_len == keylen || filename[keylen] == '/' || filename[keylen] == '\0')) { PHAR_STR_FREE(str_key); if (FAILURE == zend_hash_get_current_data(&(PHAR_GLOBALS->phar_fname_map), (void **) &pphar)) { break; } *ext_str = filename + (keylen - (*pphar)->ext_len); goto woohoo; } PHAR_STR_FREE(str_key); zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map)); } if (PHAR_G(manifest_cached)) { zend_hash_internal_pointer_reset(&cached_phars); while (FAILURE != zend_hash_has_more_elements(&cached_phars)) { if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&cached_phars, &key, &keylen, &unused, 0, NULL)) { break; } PHAR_STR(key, str_key); if (keylen > (uint) filename_len) { zend_hash_move_forward(&cached_phars); PHAR_STR_FREE(str_key); continue; } if (!memcmp(filename, str_key, keylen) && ((uint)filename_len == keylen || filename[keylen] == '/' || filename[keylen] == '\0')) { PHAR_STR_FREE(str_key); if (FAILURE == zend_hash_get_current_data(&cached_phars, (void **) &pphar)) { break; } *ext_str = filename + (keylen - (*pphar)->ext_len); goto woohoo; } PHAR_STR_FREE(str_key); zend_hash_move_forward(&cached_phars); } } } } pos = memchr(filename + 1, '.', filename_len); next_extension: if (!pos) { return FAILURE; } while (pos != filename && (*(pos - 1) == '/' || *(pos - 1) == '\0')) { pos = memchr(pos + 1, '.', filename_len - (pos - filename) + 1); if (!pos) { return FAILURE; } } slash = memchr(pos, '/', filename_len - (pos - filename)); if (!slash) { /* this is a url like "phar://blah.phar" with no directory */ *ext_str = pos; *ext_len = strlen(pos); /* file extension must contain "phar" */ switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create TSRMLS_CC)) { case SUCCESS: return SUCCESS; case FAILURE: /* we are at the end of the string, so we fail */ return FAILURE; } } /* we've found an extension that ends at a directory separator */ *ext_str = pos; *ext_len = slash - pos; switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create TSRMLS_CC)) { case SUCCESS: return SUCCESS; case FAILURE: /* look for more extensions */ pos = strchr(pos + 1, '.'); if (pos) { *ext_str = NULL; *ext_len = 0; } goto next_extension; } return FAILURE; } /* }}} */
@@ -2142,7 +2142,7 @@ char *tsrm_strtok_r(char *s, const char *delim, char **last) /* {{{ */ */ char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC) /* {{{ */ { - char newpath[MAXPATHLEN]; + char *newpath; int newpath_len; char *ptr; char *tok; @@ -2150,8 +2150,10 @@ char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC) /* {{{ if (PHAR_G(cwd_len) && use_cwd && path_length > 2 && path[0] == '.' && path[1] == '/') { newpath_len = PHAR_G(cwd_len); + newpath = emalloc(strlen(path) + newpath_len + 1); memcpy(newpath, PHAR_G(cwd), newpath_len); } else { + newpath = emalloc(strlen(path) + 2); newpath[0] = '/'; newpath_len = 1; } @@ -2174,6 +2176,7 @@ char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC) /* {{{ if (*tok == '.') { efree(path); *new_len = 1; + efree(newpath); return estrndup("/", 1); } break; @@ -2181,9 +2184,11 @@ char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC) /* {{{ if (tok[0] == '.' && tok[1] == '.') { efree(path); *new_len = 1; + efree(newpath); return estrndup("/", 1); } } + efree(newpath); return path; } @@ -2232,7 +2237,8 @@ last_time: efree(path); *new_len = newpath_len; - return estrndup(newpath, newpath_len); + newpath[newpath_len] = '\0'; + return erealloc(newpath, newpath_len + 1); } /* }}} */
CWE-119
null
null
11,783
av_cold void ff_h263_decode_init_vlc(void) { static int done = 0; if (!done) { done = 1; INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, ff_h263_intra_MCBPC_bits, 1, 1, ff_h263_intra_MCBPC_code, 1, 1, 72); INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, ff_h263_inter_MCBPC_bits, 1, 1, ff_h263_inter_MCBPC_code, 1, 1, 198); INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16, &ff_h263_cbpy_tab[0][1], 2, 1, &ff_h263_cbpy_tab[0][0], 2, 1, 64); INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, &ff_mvtab[0][1], 2, 1, &ff_mvtab[0][0], 2, 1, 538); ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]); INIT_VLC_RL(ff_h263_rl_inter, 554); INIT_VLC_RL(ff_rl_intra_aic, 554); INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, &ff_h263_mbtype_b_tab[0][1], 2, 1, &ff_h263_mbtype_b_tab[0][0], 2, 1, 80); INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, &ff_cbpc_b_tab[0][1], 2, 1, &ff_cbpc_b_tab[0][0], 2, 1, 8); } }
DoS
0
av_cold void ff_h263_decode_init_vlc(void) { static int done = 0; if (!done) { done = 1; INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, ff_h263_intra_MCBPC_bits, 1, 1, ff_h263_intra_MCBPC_code, 1, 1, 72); INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, ff_h263_inter_MCBPC_bits, 1, 1, ff_h263_inter_MCBPC_code, 1, 1, 198); INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16, &ff_h263_cbpy_tab[0][1], 2, 1, &ff_h263_cbpy_tab[0][0], 2, 1, 64); INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, &ff_mvtab[0][1], 2, 1, &ff_mvtab[0][0], 2, 1, 538); ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]); INIT_VLC_RL(ff_h263_rl_inter, 554); INIT_VLC_RL(ff_rl_intra_aic, 554); INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, &ff_h263_mbtype_b_tab[0][1], 2, 1, &ff_h263_mbtype_b_tab[0][0], 2, 1, 80); INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, &ff_cbpc_b_tab[0][1], 2, 1, &ff_cbpc_b_tab[0][0], 2, 1, 8); } }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,784
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64]) { int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; int16_t *mot_val; const int xy= s->mb_x + s->mb_y * s->mb_stride; int cbpb = 0, pb_mv_count = 0; assert(!s->h263_pred); if (s->pict_type == AV_PICTURE_TYPE_P) { do{ if (get_bits1(&s->gb)) { /* skip mb */ s->mb_intra = 0; for(i=0;i<6;i++) s->block_last_index[i] = -1; s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->mb_skipped = !(s->obmc | s->loop_filter); goto end; } cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 20); s->bdsp.clear_blocks(s->block[0]); dquant = cbpc & 8; s->mb_intra = ((cbpc & 4) != 0); if (s->mb_intra) goto intra; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } s->mv_dir = MV_DIR_FORWARD; if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ s->mv_type = MV_TYPE_16X16; ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][0][0] = mx; s->mv[0][0][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ } else { s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; s->mv_type = MV_TYPE_8X8; for(i=0;i<4;i++) { mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][i][0] = mx; s->mv[0][i][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ mot_val[0] = mx; mot_val[1] = my; } } } else if(s->pict_type==AV_PICTURE_TYPE_B) { int mb_type; const int stride= s->b8_stride; int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; do{ mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); if (mb_type < 0){ av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } mb_type= h263_mb_type_b_map[ mb_type ]; }while(!mb_type); s->mb_intra = IS_INTRA(mb_type); if(HAS_CBP(mb_type)){ s->bdsp.clear_blocks(s->block[0]); cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); if(s->mb_intra){ dquant = IS_QUANT(mb_type); goto intra; } cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if (cbpy < 0){ av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); }else cbp=0; assert(!s->mb_intra); if(IS_QUANT(mb_type)){ h263_decode_dquant(s); } if(IS_DIRECT(mb_type)){ if (!s->pp_time) return AVERROR_INVALIDDATA; s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); }else{ s->mv_dir = 0; s->mv_type= MV_TYPE_16X16; if(USES_LIST(mb_type, 0)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my); s->mv_dir = MV_DIR_FORWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[0][0][0] = mx; s->mv[0][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } if(USES_LIST(mb_type, 1)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my); s->mv_dir |= MV_DIR_BACKWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[1][0][0] = mx; s->mv[1][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } } s->current_picture.mb_type[xy] = mb_type; } else { /* I-Frame */ do{ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 8); s->bdsp.clear_blocks(s->block[0]); dquant = cbpc & 4; s->mb_intra = 1; intra: s->current_picture.mb_type[xy] = MB_TYPE_INTRA; if (s->h263_aic) { s->ac_pred = get_bits1(&s->gb); if(s->ac_pred){ s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; s->h263_aic_dir = get_bits1(&s->gb); } }else s->ac_pred = 0; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } pb_mv_count += !!s->pb_frame; } while(pb_mv_count--){ ff_h263_decode_motion(s, 0, 1); ff_h263_decode_motion(s, 0, 1); } /* decode each block */ for (i = 0; i < 6; i++) { if (h263_decode_block(s, block[i], i, cbp&32) < 0) return -1; cbp+=cbp; } if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) return -1; if(s->obmc && !s->mb_intra){ if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1) preview_obmc(s); } end: /* per-MB end of slice check */ { int v= show_bits(&s->gb, 16); if (get_bits_left(&s->gb) < 16) { v >>= 16 - get_bits_left(&s->gb); } if(v==0) return SLICE_END; } return SLICE_OK; }
DoS
0
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64]) { int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; int16_t *mot_val; const int xy= s->mb_x + s->mb_y * s->mb_stride; int cbpb = 0, pb_mv_count = 0; assert(!s->h263_pred); if (s->pict_type == AV_PICTURE_TYPE_P) { do{ if (get_bits1(&s->gb)) { /* skip mb */ s->mb_intra = 0; for(i=0;i<6;i++) s->block_last_index[i] = -1; s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->mb_skipped = !(s->obmc | s->loop_filter); goto end; } cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 20); s->bdsp.clear_blocks(s->block[0]); dquant = cbpc & 8; s->mb_intra = ((cbpc & 4) != 0); if (s->mb_intra) goto intra; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } s->mv_dir = MV_DIR_FORWARD; if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ s->mv_type = MV_TYPE_16X16; ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][0][0] = mx; s->mv[0][0][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ } else { s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; s->mv_type = MV_TYPE_8X8; for(i=0;i<4;i++) { mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][i][0] = mx; s->mv[0][i][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ mot_val[0] = mx; mot_val[1] = my; } } } else if(s->pict_type==AV_PICTURE_TYPE_B) { int mb_type; const int stride= s->b8_stride; int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; do{ mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); if (mb_type < 0){ av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } mb_type= h263_mb_type_b_map[ mb_type ]; }while(!mb_type); s->mb_intra = IS_INTRA(mb_type); if(HAS_CBP(mb_type)){ s->bdsp.clear_blocks(s->block[0]); cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); if(s->mb_intra){ dquant = IS_QUANT(mb_type); goto intra; } cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if (cbpy < 0){ av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); }else cbp=0; assert(!s->mb_intra); if(IS_QUANT(mb_type)){ h263_decode_dquant(s); } if(IS_DIRECT(mb_type)){ if (!s->pp_time) return AVERROR_INVALIDDATA; s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); }else{ s->mv_dir = 0; s->mv_type= MV_TYPE_16X16; if(USES_LIST(mb_type, 0)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my); s->mv_dir = MV_DIR_FORWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[0][0][0] = mx; s->mv[0][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } if(USES_LIST(mb_type, 1)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my); s->mv_dir |= MV_DIR_BACKWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[1][0][0] = mx; s->mv[1][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } } s->current_picture.mb_type[xy] = mb_type; } else { /* I-Frame */ do{ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 8); s->bdsp.clear_blocks(s->block[0]); dquant = cbpc & 4; s->mb_intra = 1; intra: s->current_picture.mb_type[xy] = MB_TYPE_INTRA; if (s->h263_aic) { s->ac_pred = get_bits1(&s->gb); if(s->ac_pred){ s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; s->h263_aic_dir = get_bits1(&s->gb); } }else s->ac_pred = 0; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } pb_mv_count += !!s->pb_frame; } while(pb_mv_count--){ ff_h263_decode_motion(s, 0, 1); ff_h263_decode_motion(s, 0, 1); } /* decode each block */ for (i = 0; i < 6; i++) { if (h263_decode_block(s, block[i], i, cbp&32) < 0) return -1; cbp+=cbp; } if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) return -1; if(s->obmc && !s->mb_intra){ if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1) preview_obmc(s); } end: /* per-MB end of slice check */ { int v= show_bits(&s->gb, 16); if (get_bits_left(&s->gb) < 16) { v >>= 16 - get_bits_left(&s->gb); } if(v==0) return SLICE_END; } return SLICE_OK; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,785
int ff_h263_decode_mba(MpegEncContext *s) { int i, mb_pos; for (i = 0; i < 6; i++) if (s->mb_num - 1 <= ff_mba_max[i]) break; mb_pos = get_bits(&s->gb, ff_mba_length[i]); s->mb_x = mb_pos % s->mb_width; s->mb_y = mb_pos / s->mb_width; return mb_pos; }
DoS
0
int ff_h263_decode_mba(MpegEncContext *s) { int i, mb_pos; for (i = 0; i < 6; i++) if (s->mb_num - 1 <= ff_mba_max[i]) break; mb_pos = get_bits(&s->gb, ff_mba_length[i]); s->mb_x = mb_pos % s->mb_width; s->mb_y = mb_pos / s->mb_width; return mb_pos; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,786
int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) { int code, val, sign, shift; code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); if (code == 0) return pred; if (code < 0) return 0xffff; sign = get_bits1(&s->gb); shift = f_code - 1; val = code; if (shift) { val = (val - 1) << shift; val |= get_bits(&s->gb, shift); val++; } if (sign) val = -val; val += pred; /* modulo decoding */ if (!s->h263_long_vectors) { val = sign_extend(val, 5 + f_code); } else { /* horrible h263 long vector mode */ if (pred < -31 && val < -63) val += 64; if (pred > 32 && val > 63) val -= 64; } return val; }
DoS
0
int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) { int code, val, sign, shift; code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); if (code == 0) return pred; if (code < 0) return 0xffff; sign = get_bits1(&s->gb); shift = f_code - 1; val = code; if (shift) { val = (val - 1) << shift; val |= get_bits(&s->gb, shift); val++; } if (sign) val = -val; val += pred; /* modulo decoding */ if (!s->h263_long_vectors) { val = sign_extend(val, 5 + f_code); } else { /* horrible h263 long vector mode */ if (pred < -31 && val < -63) val += 64; if (pred > 32 && val > 63) val -= 64; } return val; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,787
void ff_h263_show_pict_info(MpegEncContext *s){ if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", s->qscale, av_get_picture_type_char(s->pict_type), s->gb.size_in_bits, 1-s->no_rounding, s->obmc ? " AP" : "", s->umvplus ? " UMV" : "", s->h263_long_vectors ? " LONG" : "", s->h263_plus ? " +" : "", s->h263_aic ? " AIC" : "", s->alt_inter_vlc ? " AIV" : "", s->modified_quant ? " MQ" : "", s->loop_filter ? " LOOP" : "", s->h263_slice_structured ? " SS" : "", s->avctx->framerate.num, s->avctx->framerate.den ); } }
DoS
0
void ff_h263_show_pict_info(MpegEncContext *s){ if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", s->qscale, av_get_picture_type_char(s->pict_type), s->gb.size_in_bits, 1-s->no_rounding, s->obmc ? " AP" : "", s->umvplus ? " UMV" : "", s->h263_long_vectors ? " LONG" : "", s->h263_plus ? " +" : "", s->h263_aic ? " AIC" : "", s->alt_inter_vlc ? " AIV" : "", s->modified_quant ? " MQ" : "", s->loop_filter ? " LOOP" : "", s->h263_slice_structured ? " SS" : "", s->avctx->framerate.num, s->avctx->framerate.den ); } }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,788
static int h263_decode_block(MpegEncContext * s, int16_t * block, int n, int coded) { int code, level, i, j, last, run; RLTable *rl = &ff_h263_rl_inter; const uint8_t *scan_table; GetBitContext gb= s->gb; scan_table = s->intra_scantable.permutated; if (s->h263_aic && s->mb_intra) { rl = &ff_rl_intra_aic; i = 0; if (s->ac_pred) { if (s->h263_aic_dir) scan_table = s->intra_v_scantable.permutated; /* left */ else scan_table = s->intra_h_scantable.permutated; /* top */ } } else if (s->mb_intra) { /* DC coef */ if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) { if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) { int component, diff; component = (n <= 3 ? 0 : n - 4 + 1); level = s->last_dc[component]; if (s->rv10_first_dc_coded[component]) { diff = ff_rv_decode_dc(s, n); if (diff == 0xffff) return -1; level += diff; level = level & 0xff; /* handle wrap round */ s->last_dc[component] = level; } else { s->rv10_first_dc_coded[component] = 1; } } else { level = get_bits(&s->gb, 8); if (level == 255) level = 128; } }else{ level = get_bits(&s->gb, 8); if((level&0x7F) == 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); if (s->avctx->err_recognition & AV_EF_BITSTREAM) return -1; } if (level == 255) level = 128; } block[0] = level; i = 1; } else { i = 0; } if (!coded) { if (s->mb_intra && s->h263_aic) goto not_coded; s->block_last_index[n] = i - 1; return 0; } retry: for(;;) { code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); return -1; } if (code == rl->n) { /* escape */ if (CONFIG_FLV_DECODER && s->h263_flv > 1) { ff_flv2_decode_ac_esc(&s->gb, &level, &run, &last); } else { last = get_bits1(&s->gb); run = get_bits(&s->gb, 6); level = (int8_t)get_bits(&s->gb, 8); if(level == -128){ if (s->codec_id == AV_CODEC_ID_RV10) { /* XXX: should patch encoder too */ level = get_sbits(&s->gb, 12); }else{ level = get_bits(&s->gb, 5); level |= get_sbits(&s->gb, 6)<<5; } } } } else { run = rl->table_run[code]; level = rl->table_level[code]; last = code >= rl->last; if (get_bits1(&s->gb)) level = -level; } i += run; if (i >= 64){ if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){ rl = &ff_rl_intra_aic; i = 0; s->gb= gb; s->bdsp.clear_block(block); goto retry; } av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); return -1; } j = scan_table[i]; block[j] = level; if (last) break; i++; } not_coded: if (s->mb_intra && s->h263_aic) { ff_h263_pred_acdc(s, block, n); i = 63; } s->block_last_index[n] = i; return 0; }
DoS
0
static int h263_decode_block(MpegEncContext * s, int16_t * block, int n, int coded) { int code, level, i, j, last, run; RLTable *rl = &ff_h263_rl_inter; const uint8_t *scan_table; GetBitContext gb= s->gb; scan_table = s->intra_scantable.permutated; if (s->h263_aic && s->mb_intra) { rl = &ff_rl_intra_aic; i = 0; if (s->ac_pred) { if (s->h263_aic_dir) scan_table = s->intra_v_scantable.permutated; /* left */ else scan_table = s->intra_h_scantable.permutated; /* top */ } } else if (s->mb_intra) { /* DC coef */ if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) { if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) { int component, diff; component = (n <= 3 ? 0 : n - 4 + 1); level = s->last_dc[component]; if (s->rv10_first_dc_coded[component]) { diff = ff_rv_decode_dc(s, n); if (diff == 0xffff) return -1; level += diff; level = level & 0xff; /* handle wrap round */ s->last_dc[component] = level; } else { s->rv10_first_dc_coded[component] = 1; } } else { level = get_bits(&s->gb, 8); if (level == 255) level = 128; } }else{ level = get_bits(&s->gb, 8); if((level&0x7F) == 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); if (s->avctx->err_recognition & AV_EF_BITSTREAM) return -1; } if (level == 255) level = 128; } block[0] = level; i = 1; } else { i = 0; } if (!coded) { if (s->mb_intra && s->h263_aic) goto not_coded; s->block_last_index[n] = i - 1; return 0; } retry: for(;;) { code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); return -1; } if (code == rl->n) { /* escape */ if (CONFIG_FLV_DECODER && s->h263_flv > 1) { ff_flv2_decode_ac_esc(&s->gb, &level, &run, &last); } else { last = get_bits1(&s->gb); run = get_bits(&s->gb, 6); level = (int8_t)get_bits(&s->gb, 8); if(level == -128){ if (s->codec_id == AV_CODEC_ID_RV10) { /* XXX: should patch encoder too */ level = get_sbits(&s->gb, 12); }else{ level = get_bits(&s->gb, 5); level |= get_sbits(&s->gb, 6)<<5; } } } } else { run = rl->table_run[code]; level = rl->table_level[code]; last = code >= rl->last; if (get_bits1(&s->gb)) level = -level; } i += run; if (i >= 64){ if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){ rl = &ff_rl_intra_aic; i = 0; s->gb= gb; s->bdsp.clear_block(block); goto retry; } av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); return -1; } j = scan_table[i]; block[j] = level; if (last) break; i++; } not_coded: if (s->mb_intra && s->h263_aic) { ff_h263_pred_acdc(s, block, n); i = 63; } s->block_last_index[n] = i; return 0; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,789
static void h263_decode_dquant(MpegEncContext *s){ static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; if(s->modified_quant){ if(get_bits1(&s->gb)) s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; else s->qscale= get_bits(&s->gb, 5); }else s->qscale += quant_tab[get_bits(&s->gb, 2)]; ff_set_qscale(s, s->qscale); }
DoS
0
static void h263_decode_dquant(MpegEncContext *s){ static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; if(s->modified_quant){ if(get_bits1(&s->gb)) s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; else s->qscale= get_bits(&s->gb, 5); }else s->qscale += quant_tab[get_bits(&s->gb, 2)]; ff_set_qscale(s, s->qscale); }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,790
static int h263_skip_b_part(MpegEncContext *s, int cbp) { LOCAL_ALIGNED_16(int16_t, dblock, [64]); int i, mbi; /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly * but real value should be restored in order to be used later (in OBMC condition) */ mbi = s->mb_intra; s->mb_intra = 0; for (i = 0; i < 6; i++) { if (h263_decode_block(s, dblock, i, cbp&32) < 0) return -1; cbp+=cbp; } s->mb_intra = mbi; return 0; }
DoS
0
static int h263_skip_b_part(MpegEncContext *s, int cbp) { LOCAL_ALIGNED_16(int16_t, dblock, [64]); int i, mbi; /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly * but real value should be restored in order to be used later (in OBMC condition) */ mbi = s->mb_intra; s->mb_intra = 0; for (i = 0; i < 6; i++) { if (h263_decode_block(s, dblock, i, cbp&32) < 0) return -1; cbp+=cbp; } s->mb_intra = mbi; return 0; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,791
static int h263p_decode_umotion(MpegEncContext * s, int pred) { int code = 0, sign; if (get_bits1(&s->gb)) /* Motion difference = 0 */ return pred; code = 2 + get_bits1(&s->gb); while (get_bits1(&s->gb)) { code <<= 1; code += get_bits1(&s->gb); } sign = code & 1; code >>= 1; code = (sign) ? (pred - code) : (pred + code); ff_dlog(s->avctx,"H.263+ UMV Motion = %d\n", code); return code; }
DoS
0
static int h263p_decode_umotion(MpegEncContext * s, int pred) { int code = 0, sign; if (get_bits1(&s->gb)) /* Motion difference = 0 */ return pred; code = 2 + get_bits1(&s->gb); while (get_bits1(&s->gb)) { code <<= 1; code += get_bits1(&s->gb); } sign = code & 1; code >>= 1; code = (sign) ? (pred - code) : (pred + code); ff_dlog(s->avctx,"H.263+ UMV Motion = %d\n", code); return code; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,792
static void preview_obmc(MpegEncContext *s){ GetBitContext gb= s->gb; int cbpc, i, pred_x, pred_y, mx, my; int16_t *mot_val; const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; const int stride= s->b8_stride*2; for(i=0; i<4; i++) s->block_index[i]+= 2; for(i=4; i<6; i++) s->block_index[i]+= 1; s->mb_x++; assert(s->pict_type == AV_PICTURE_TYPE_P); do{ if (get_bits1(&s->gb)) { /* skip mb */ mot_val = s->current_picture.motion_val[0][s->block_index[0]]; mot_val[0 ]= mot_val[2 ]= mot_val[0+stride]= mot_val[2+stride]= 0; mot_val[1 ]= mot_val[3 ]= mot_val[1+stride]= mot_val[3+stride]= 0; s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; goto end; } cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); }while(cbpc == 20); if(cbpc & 4){ s->current_picture.mb_type[xy] = MB_TYPE_INTRA; }else{ get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if (cbpc & 8) { if(s->modified_quant){ if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); else skip_bits(&s->gb, 5); }else skip_bits(&s->gb, 2); } if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); mot_val[0 ]= mot_val[2 ]= mot_val[0+stride]= mot_val[2+stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+stride]= mot_val[3+stride]= my; } else { s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; for(i=0;i<4;i++) { mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ mot_val[0] = mx; mot_val[1] = my; } } } end: for(i=0; i<4; i++) s->block_index[i]-= 2; for(i=4; i<6; i++) s->block_index[i]-= 1; s->mb_x--; s->gb= gb; }
DoS
0
static void preview_obmc(MpegEncContext *s){ GetBitContext gb= s->gb; int cbpc, i, pred_x, pred_y, mx, my; int16_t *mot_val; const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; const int stride= s->b8_stride*2; for(i=0; i<4; i++) s->block_index[i]+= 2; for(i=4; i<6; i++) s->block_index[i]+= 1; s->mb_x++; assert(s->pict_type == AV_PICTURE_TYPE_P); do{ if (get_bits1(&s->gb)) { /* skip mb */ mot_val = s->current_picture.motion_val[0][s->block_index[0]]; mot_val[0 ]= mot_val[2 ]= mot_val[0+stride]= mot_val[2+stride]= 0; mot_val[1 ]= mot_val[3 ]= mot_val[1+stride]= mot_val[3+stride]= 0; s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; goto end; } cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); }while(cbpc == 20); if(cbpc & 4){ s->current_picture.mb_type[xy] = MB_TYPE_INTRA; }else{ get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if (cbpc & 8) { if(s->modified_quant){ if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); else skip_bits(&s->gb, 5); }else skip_bits(&s->gb, 2); } if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); mot_val[0 ]= mot_val[2 ]= mot_val[0+stride]= mot_val[2+stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+stride]= mot_val[3+stride]= my; } else { s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; for(i=0;i<4;i++) { mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ mot_val[0] = mx; mot_val[1] = my; } } } end: for(i=0; i<4; i++) s->block_index[i]-= 2; for(i=4; i<6; i++) s->block_index[i]-= 1; s->mb_x--; s->gb= gb; }
@@ -30,6 +30,7 @@ #include <limits.h> #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "avcodec.h" @@ -868,7 +869,7 @@ end: /* most is hardcoded. should extend to handle all h263 streams */ int ff_h263_decode_picture_header(MpegEncContext *s) { - int format, width, height, i; + int format, width, height, i, ret; uint32_t startcode; align_get_bits(&s->gb); @@ -919,8 +920,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s) /* H.263v1 */ width = ff_h263_format[format][0]; height = ff_h263_format[format][1]; - if (!width) - return -1; s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); @@ -1073,6 +1072,9 @@ int ff_h263_decode_picture_header(MpegEncContext *s) s->qscale = get_bits(&s->gb, 5); } + if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0) + return ret; + s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height;
CWE-189
null
null
11,793
JBIG2Bitmap::JBIG2Bitmap(Guint segNumA, JBIG2Bitmap *bitmap): JBIG2Segment(segNumA) { if (unlikely(bitmap == NULL)) { error(errSyntaxError, -1, "NULL bitmap in JBIG2Bitmap"); w = h = line = 0; data = NULL; return; } w = bitmap->w; h = bitmap->h; line = bitmap->line; if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) { error(errSyntaxError, -1, "invalid width/height"); data = NULL; return; } data = (Guchar *)gmalloc(h * line + 1); memcpy(data, bitmap->data, h * line); data[h * line] = 0; }
DoS Overflow
0
JBIG2Bitmap::JBIG2Bitmap(Guint segNumA, JBIG2Bitmap *bitmap): JBIG2Segment(segNumA) { if (unlikely(bitmap == NULL)) { error(errSyntaxError, -1, "NULL bitmap in JBIG2Bitmap"); w = h = line = 0; data = NULL; return; } w = bitmap->w; h = bitmap->h; line = bitmap->line; if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) { error(errSyntaxError, -1, "invalid width/height"); data = NULL; return; } data = (Guchar *)gmalloc(h * line + 1); memcpy(data, bitmap->data, h * line); data[h * line] = 0; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,794
void JBIG2Bitmap::expand(int newH, Guint pixel) { if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) { error(errSyntaxError, -1, "invalid width/height"); gfree(data); data = NULL; return; } data = (Guchar *)grealloc(data, newH * line + 1); if (pixel) { memset(data + h * line, 0xff, (newH - h) * line); } else { memset(data + h * line, 0x00, (newH - h) * line); } h = newH; data[h * line] = 0; }
DoS Overflow
0
void JBIG2Bitmap::expand(int newH, Guint pixel) { if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) { error(errSyntaxError, -1, "invalid width/height"); gfree(data); data = NULL; return; } data = (Guchar *)grealloc(data, newH * line + 1); if (pixel) { memset(data + h * line, 0xff, (newH - h) * line); } else { memset(data + h * line, 0x00, (newH - h) * line); } h = newH; data[h * line] = 0; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,795
JBIG2Bitmap *getBitmap(Guint idx) { return (idx < size) ? bitmaps[idx] : NULL; }
DoS Overflow
0
JBIG2Bitmap *getBitmap(Guint idx) { return (idx < size) ? bitmaps[idx] : NULL; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,796
int JBIG2MMRDecoder::getBlackCode() { const CCITTCode *p; Guint code; if (bufLen == 0) { buf = str->getChar() & 0xff; bufLen = 8; ++nBytesRead; } while (1) { if (bufLen >= 10 && ((buf >> (bufLen - 6)) & 0x3f) == 0) { if (bufLen <= 13) { code = buf << (13 - bufLen); } else { code = buf >> (bufLen - 13); } p = &blackTab1[code & 0x7f]; } else if (bufLen >= 7 && ((buf >> (bufLen - 4)) & 0x0f) == 0 && ((buf >> (bufLen - 6)) & 0x03) != 0) { if (bufLen <= 12) { code = buf << (12 - bufLen); } else { code = buf >> (bufLen - 12); } if (unlikely((code & 0xff) < 64)) { break; } p = &blackTab2[(code & 0xff) - 64]; } else { if (bufLen <= 6) { code = buf << (6 - bufLen); } else { code = buf >> (bufLen - 6); } p = &blackTab3[code & 0x3f]; } if (p->bits > 0 && p->bits <= (int)bufLen) { bufLen -= p->bits; return p->n; } if (bufLen >= 13) { break; } buf = (buf << 8) | (str->getChar() & 0xff); bufLen += 8; ++nBytesRead; } error(errSyntaxError, str->getPos(), "Bad black code in JBIG2 MMR stream"); --bufLen; return 1; }
DoS Overflow
0
int JBIG2MMRDecoder::getBlackCode() { const CCITTCode *p; Guint code; if (bufLen == 0) { buf = str->getChar() & 0xff; bufLen = 8; ++nBytesRead; } while (1) { if (bufLen >= 10 && ((buf >> (bufLen - 6)) & 0x3f) == 0) { if (bufLen <= 13) { code = buf << (13 - bufLen); } else { code = buf >> (bufLen - 13); } p = &blackTab1[code & 0x7f]; } else if (bufLen >= 7 && ((buf >> (bufLen - 4)) & 0x0f) == 0 && ((buf >> (bufLen - 6)) & 0x03) != 0) { if (bufLen <= 12) { code = buf << (12 - bufLen); } else { code = buf >> (bufLen - 12); } if (unlikely((code & 0xff) < 64)) { break; } p = &blackTab2[(code & 0xff) - 64]; } else { if (bufLen <= 6) { code = buf << (6 - bufLen); } else { code = buf >> (bufLen - 6); } p = &blackTab3[code & 0x3f]; } if (p->bits > 0 && p->bits <= (int)bufLen) { bufLen -= p->bits; return p->n; } if (bufLen >= 13) { break; } buf = (buf << 8) | (str->getChar() & 0xff); bufLen += 8; ++nBytesRead; } error(errSyntaxError, str->getPos(), "Bad black code in JBIG2 MMR stream"); --bufLen; return 1; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,797
int JBIG2Stream::getChars(int nChars, Guchar *buffer) { int n, i; if (nChars <= 0) { return 0; } if (dataEnd - dataPtr < nChars) { n = (int)(dataEnd - dataPtr); } else { n = nChars; } for (i = 0; i < n; ++i) { buffer[i] = *dataPtr++ ^ 0xff; } return n; }
DoS Overflow
0
int JBIG2Stream::getChars(int nChars, Guchar *buffer) { int n, i; if (nChars <= 0) { return 0; } if (dataEnd - dataPtr < nChars) { n = (int)(dataEnd - dataPtr); } else { n = nChars; } for (i = 0; i < n; ++i) { buffer[i] = *dataPtr++ ^ 0xff; } return n; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,798
int getLineSize() { return line; }
DoS Overflow
0
int getLineSize() { return line; }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null
11,799
inline void JBIG2Bitmap::getPixelPtr(int x, int y, JBIG2BitmapPtr *ptr) { if (y < 0 || y >= h || x >= w) { ptr->p = NULL; ptr->shift = 0; // make gcc happy ptr->x = 0; // make gcc happy } else if (x < 0) { ptr->p = &data[y * line]; ptr->shift = 7; ptr->x = x; } else { ptr->p = &data[y * line + (x >> 3)]; ptr->shift = 7 - (x & 7); ptr->x = x; } }
DoS Overflow
0
inline void JBIG2Bitmap::getPixelPtr(int x, int y, JBIG2BitmapPtr *ptr) { if (y < 0 || y >= h || x >= w) { ptr->p = NULL; ptr->shift = 0; // make gcc happy ptr->x = 0; // make gcc happy } else if (x < 0) { ptr->p = &data[y * line]; ptr->shift = 7; ptr->x = x; } else { ptr->p = &data[y * line + (x >> 3)]; ptr->shift = 7 - (x & 7); ptr->x = x; } }
@@ -1495,7 +1495,7 @@ void JBIG2Stream::readSegments() { // arithmetic-coded symbol dictionary segments when numNewSyms // == 0. Segments like this often occur for blank pages. - error(errSyntaxError, curStr->getPos(), "{0:d} extraneous byte{1:s} after segment", + error(errSyntaxError, curStr->getPos(), "{0:lld} extraneous byte{1:s} after segment", segExtraBytes, (segExtraBytes > 1) ? "s" : ""); // Burn through the remaining bytes -- inefficient, but
CWE-119
null
null