Commit Graph

3479 Commits

Author SHA1 Message Date
Todd C. Miller
e3583e01b8 The sample plugin is now built by default to avoid bit rot.
GitHub issue #234.
2023-01-19 07:38:51 -07:00
Todd C. Miller
4f9da47e55 The change from sudo_printf -> sudo_plugin_printf was incomplete.
Fixes GitHub issue #234.
2023-01-19 07:38:29 -07:00
Todd C. Miller
7ff70c09fe Update expected plugin version. 2023-01-18 13:53:33 -07:00
Todd C. Miller
0865e61d9e Pass back the number of files to edit when using sudoedit.
The sudo front-end can use this to determine where the list of files
to edit begins.
2023-01-18 13:38:15 -07:00
Todd C. Miller
334daf92b3 Escape control characters in log messages and "sudoreplay -l" output.
The log message contains user-controlled strings that could include
things like terminal control characters.  Space characters in the
command path are now also escaped.

Command line arguments that contain spaces are surrounded with
single quotes and any literal single quote or backslash characters
are escaped with a backslash.  This makes it possible to distinguish
multiple command line arguments from a single argument that contains
spaces.

Issue found by Matthieu Barjole and Victor Cutillas of Synacktiv
(https://synacktiv.com).
2023-01-18 08:21:34 -07:00
Todd C. Miller
0274a4f3b4 sudoedit: do not permit editor arguments to include "--" (CVE-2023-22809)
We use "--" to separate the editor and arguments from the files to edit.
If the editor arguments include "--", sudo can be tricked into allowing
the user to edit a file not permitted by the security policy.
Thanks to Matthieu Barjole and Victor Cutillas of Synacktiv
(https://synacktiv.com) for finding this bug.
2023-01-12 15:55:27 -07:00
Todd C. Miller
3878ce8d49 env_file_next_local: change the order of the val_len check.
It makes more sense to verify that val_len > 1 before using it.
This is not a problem in practice because val[val_len - 1] is
guaranteed not to underflow but it can confuse reviewers and static
analyzers.
2023-01-09 14:26:07 -07:00
Todd C. Miller
d781ab0a89 Fix typo in check for environment variables that start with '='. 2023-01-09 14:23:50 -07:00
Todd C. Miller
1f58e5a8e0 Fix IS_IDLOG macro, it was testing the wrong byte for the NUL.
This causes the macro to evaluate to false even for valid TSIDs.
2023-01-09 13:03:55 -07:00
Todd C. Miller
8309fbb970 sudoers_trace_print: this is a no-op if not debugging 2023-01-04 10:44:58 -07:00
Todd C. Miller
e5d98da014 Move hexchar() from the sudoers plugin to lib/util. 2023-01-03 15:50:42 -07:00
Sohom
761ffb3bfe Prevent integer underflow due to environment variable
Gaurd against replacing quotes when the environment variable
val_len is 1.
2023-01-02 11:47:52 +05:30
Todd C. Miller
91d7592e8a Use initprogname(), not setprogname() in the fuzzers.
This results in better coverage for progname.c.
2022-12-29 15:52:21 -07:00
Todd C. Miller
3f095ff1b5 Disable sudo_debug tests when fuzzing.
The debug code is disable when fuzzing is enabled to avoid coverage
issues.
2022-12-29 12:38:00 -07:00
Todd C. Miller
8a5e9ffb43 Plug memory leak. 2022-12-29 10:35:09 -07:00
Todd C. Miller
47a211f194 Update fuzz_policy keywords to match current policy settings. 2022-12-28 16:02:25 -07:00
Todd C. Miller
a7c1b78c67 Add example users and groups to the dictionary. 2022-12-28 16:02:10 -07:00
Todd C. Miller
8eabbf8fdd parse_args: an environment variable may not start with '='.
Also check VAR=val format in validate_env_vars() and add an error
message if insert_env_vars() fails.
2022-12-28 14:07:43 -07:00
Todd C. Miller
c820599893 rebuild_env: avoid a potential NULL dereference in fuzz_policy 2022-12-28 11:05:17 -07:00
Todd C. Miller
b69ffd3479 sudoers_policy_main: plug memory leak of iolog_path on error. 2022-12-28 10:50:51 -07:00
Todd C. Miller
8e8a22b8e5 rebuild_env: avoid a potential NULL dereference in fuzz_policy 2022-12-28 09:45:01 -07:00
Todd C. Miller
bca945f074 The contents of the env_add array should not include the leading "env=" prefix.
The previous fix for this was incomplete.
2022-12-28 09:25:41 -07:00
Todd C. Miller
9c4271f737 validate_env_vars: more efficient errbuf handling
Also avoid appending to errbuf if it is already full.
2022-12-28 09:24:22 -07:00
Todd C. Miller
fa1b86fca6 Remove the Python plugin import blocker code.
The sudo.conf file is considered a trusted source of information
and these checks suffer from TOCTOU issues anyway.
2022-12-26 07:43:55 -07:00
Todd C. Miller
73abff2d05 Remove the owner and mode checks when loading a sudo plugin.
The sudo.conf file is considered a trusted source of information
and these checks suffer from TOCTOU issues anyway.  The checks
complicate loading of shared objects since we need to perform
fallback processing twice.
2022-12-26 07:43:55 -07:00
Todd C. Miller
5165fb9b22 Bump SUDOERS_GRAMMAR_VERSION to 50 for the new list pseudo-command. 2022-12-26 07:41:53 -07:00
Todd C. Miller
797cc917a8 Add basic regress for JSON functions.
Fix a bug in escaped control character handling.
Roll back changes to buffer if sudo_json_add_value() fails.
2022-12-15 19:49:11 -07:00
Todd C. Miller
0e6482e827 Add missing memory allocation failure checks.
Inspired by GitHub PR #221
2022-12-15 09:30:49 -07:00
Todd C. Miller
62dd5734a2 Plug a memory leak of list_cmnd in the fuzzers. 2022-12-11 14:29:14 -07:00
Todd C. Miller
25c709c4d8 Suppress PVS Studio watning about reassigning a variable the same value.
Working around the warning would result in more fragile code.
2022-12-11 13:46:06 -07:00
Todd C. Miller
f26a2e7626 Fix some dead stores noted by PVS Studio.
Since rc is initialized to SUDO_RC_ERROR there is no need to set
it to SUDO_RC_ERROR again on failure if rc has not been changed
since initialization.
2022-12-11 13:46:04 -07:00
Todd C. Miller
a514a6eed5 Add "list" pseudo-command to allow a user to list another user's
privs.  Previously, only root or a user with the ability to run any
command as either root or the target user on the current host could
use the -U option.  For "sudo -l [-U otheruser] command", NewArgv[0]
is now set to "list" (just like "sudo -l") and the actual command
to be checked starts with NewArgv[1].
2022-12-11 13:46:00 -07:00
Todd C. Miller
f5488d733d Fix potential crash introduced in the fix for GitHub issue #134.
If a user's sudoers entry did not have any RunAs user's set, running
"sudo -U otheruser -l" would dereference a NULL pointer.  We need
to compare the default RunAs user if the sudoers entry does not
specify one explicitly.  Problem reported by Andreas Mueller who
also suggested a different solution in PR #219.
2022-12-07 10:25:00 -07:00
Todd C. Miller
3df7b64d80 Fix failure in check targets when there is no UTF-8 C locale. 2022-12-06 16:26:34 -07:00
Todd C. Miller
e707ffe58b Place C23 attributes before keywords in function declarations.
In practice this means we must use "sudo_noreturn static foo(void)"
instead of "static sudo_noreturn foo(void)".
2022-12-01 12:54:53 -07:00
modric
26cf125fb9 check_syntax(): Remove duplicate calls to init_defaults() 2022-11-24 09:42:05 +08:00
Todd C. Miller
46d286947e build_command_info: free command_info on failure.
Once upon a time, command_info was a stack variable, now it is
dynamically allocated.  Coverity CID 299987.
2022-11-22 17:26:24 -07:00
Todd C. Miller
eb4ae10ab4 Better handling of out-of-memory conditions. 2022-11-22 11:57:42 -07:00
Todd C. Miller
9fff5a5fae Keep group file open until the call to myendgrent().
This restores the previous behavior.
2022-11-22 11:55:34 -07:00
Todd C. Miller
f066ff9e01 Eliminate a few harmless dead stores.
Quiets warnings from Infer.
2022-11-22 11:18:24 -07:00
Todd C. Miller
2f97da316e sudo_ldap_parse_option: add explicit NULL check for strchr().
This should not be needed since we only use the returned pointer
if it is larger than the string passed to strchr().
Quiets a warning from Infer.
2022-11-22 11:17:30 -07:00
Todd C. Miller
a37ecb2666 sudo_ldap_result_add_entry: check sudo_ldap_get_values_len() return value.
Previously, we just compared the error code with LDAP_NO_MEMORY
when checking for sudoOrder since this is the only error we care about.
We now return NULL for LDAP_NO_MEMORY and ignore other errors.
Quiets a warning from Infer.
2022-11-22 11:05:26 -07:00
Todd C. Miller
1c9c7bd34a Refactor code to open passwd/group file and add setpassent/setgroupent.
This makes the "stayopen" semantics match the system passwd/group
functions.  The getpwent/getgrent functions now open the database
if it is not already open.
2022-11-22 08:45:14 -07:00
Todd C. Miller
4d7823e518 gram.h: #line directives should reference gram.h not y.tab.h. 2022-11-22 07:27:11 -07:00
Todd C. Miller
3396267291 Add a reminder to the default lecture that the password will not echo.
This line is only displayed when the pwfeedback option is disabled.
GitHub issue #195.
2022-11-21 09:48:50 -07:00
modric
cbdc4883d1 Fix some typos 2022-11-21 14:50:22 +08:00
Todd C. Miller
ad220d72d4 Merge pull request #200 from BornThisWay/fix_mem_leak_converse
Fix memory leak of pass in converse().
2022-11-17 08:16:40 -07:00
Todd C. Miller
b3834bbf24 sudo_passwd_cleanup: Set auth->data to NULL after freeing.
GitHub issue #201
2022-11-17 08:10:35 -07:00
modric
f5cae905ca Fix memory leak of pass in converse(). 2022-11-17 16:08:59 +08:00
Todd C. Miller
fe8e1f3d38 Fix typo; excerise -> exercise 2022-11-16 19:23:11 -07:00