@@ -547,7 +547,7 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
547
547
548
548
/* If run as root with SUDO_USER set, set sudo_user.pw to that user. */
549
549
/* XXX - causes confusion when root is not listed in sudoers */
550
- if (sudo_mode & ( MODE_RUN | MODE_EDIT ) && prev_user != NULL ) {
550
+ if (ISSET ( sudo_mode , MODE_RUN | MODE_EDIT ) && prev_user != NULL ) {
551
551
if (user_uid == 0 && strcmp (prev_user , "root" ) != 0 ) {
552
552
struct passwd * pw ;
553
553
@@ -932,8 +932,8 @@ set_cmnd(void)
932
932
if (user_cmnd == NULL )
933
933
user_cmnd = NewArgv [0 ];
934
934
935
- if (sudo_mode & ( MODE_RUN | MODE_EDIT | MODE_CHECK )) {
936
- if (ISSET (sudo_mode , MODE_RUN | MODE_CHECK )) {
935
+ if (ISSET ( sudo_mode , MODE_RUN | MODE_EDIT | MODE_CHECK )) {
936
+ if (! ISSET (sudo_mode , MODE_EDIT )) {
937
937
const char * runchroot = user_runchroot ;
938
938
if (runchroot == NULL && def_runchroot != NULL &&
939
939
strcmp (def_runchroot , "*" ) != 0 )
@@ -961,18 +961,31 @@ set_cmnd(void)
961
961
sudo_warnx (U_ ("%s: %s" ), __func__ , U_ ("unable to allocate memory" ));
962
962
debug_return_int (NOT_FOUND_ERROR );
963
963
}
964
- if (ISSET (sudo_mode , MODE_SHELL |MODE_LOGIN_SHELL )) {
964
+ if (ISSET (sudo_mode , MODE_SHELL |MODE_LOGIN_SHELL ) &&
965
+ ISSET (sudo_mode , MODE_RUN )) {
965
966
/*
966
967
* When running a command via a shell, the sudo front-end
967
968
* escapes potential meta chars. We unescape non-spaces
968
969
* for sudoers matching and logging purposes.
969
970
*/
970
971
for (to = user_args , av = NewArgv + 1 ; (from = * av ); av ++ ) {
971
972
while (* from ) {
972
- if (from [0 ] == '\\' && !isspace ((unsigned char )from [1 ]))
973
+ if (from [0 ] == '\\' && from [1 ] != '\0' &&
974
+ !isspace ((unsigned char )from [1 ])) {
973
975
from ++ ;
976
+ }
977
+ if (size - (to - user_args ) < 1 ) {
978
+ sudo_warnx (U_ ("internal error, %s overflow" ),
979
+ __func__ );
980
+ debug_return_int (NOT_FOUND_ERROR );
981
+ }
974
982
* to ++ = * from ++ ;
975
983
}
984
+ if (size - (to - user_args ) < 1 ) {
985
+ sudo_warnx (U_ ("internal error, %s overflow" ),
986
+ __func__ );
987
+ debug_return_int (NOT_FOUND_ERROR );
988
+ }
976
989
* to ++ = ' ' ;
977
990
}
978
991
* -- to = '\0' ;
0 commit comments