shadow-maint / shadow

Upstream shadow tree
Other
290 stars 228 forks source link

Fix coverity unbounded source buffer issues #989

Open MarcinDigitic opened 2 months ago

MarcinDigitic commented 2 months ago

Fix coverity unbound buffer issues

During coverity scan, there are reported four issues with unbounded source buffer for each usage of input arg directly with syslog function.

Sample coverity test report for chsh.c file:

  1. string_size_argv: argv contains strings with unknown size. int main (int argc, char **argv) [...]
  2. var_assign_var: Assigning: user = argv[optind]. Both are now tainted. user = argv[optind]; [...] CID 5771784: (#1 of 1): Unbounded source buffer (STRING_SIZE)
    1. string_size: Passing string user of unknown size to syslog. SYSLOG ((LOG_INFO, "changed user '%s' shell to '%s'", user, loginsh));

Similar issue is reported three times more: File: chfn.c, function: main, variable: user File: passwd.c, function: main, variable: name File: newgrp.c, function: main, variable: group

The proposed commit is a try to fix the reported issues by adding a check for a valid user or group names.

alejandro-colomar commented 2 months ago

During coverity scan, there is reported an issue with unbounded source buffer for each usage of input arg directly with syslog function.

Please paste such a Coverity scan report in the commit message. It would be helpful when reviewing.

alejandro-colomar commented 2 months ago

Can you please rebase the branch?


Edit: I've done it myself for you.

v1b:

$ git range-diff md/master..md/topic/coverity/fix_unbound_input_buffer shadow/master..989 
1:  a90453e6 = 1:  bb741102 Fix coverity unbound buffer issues
alejandro-colomar commented 2 months ago

Please address the issues raised.

alejandro-colomar commented 2 months ago

I've converted your PR to draft, since it's not ready for review. Please address the comments.