brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · f7abc71 Raw
74 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s     \2// RUN:   -analyzer-checker=core,security.cert.env.InvalidPtr       \3// RUN:   -verify=putenv,common                                     \4// RUN:   -DENV_INVALIDATING_CALL="putenv(\"X=Y\")"5//6// RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s     \7// RUN:   -analyzer-checker=core,security.cert.env.InvalidPtr       \8// RUN:   -verify=putenvs,common                                    \9// RUN:   -DENV_INVALIDATING_CALL="_putenv_s(\"X\", \"Y\")"10//11// RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s     \12// RUN:   -analyzer-checker=core,security.cert.env.InvalidPtr       \13// RUN:   -verify=wputenvs,common                                   \14// RUN:   -DENV_INVALIDATING_CALL="_wputenv_s(\"X\", \"Y\")"15//16// RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s     \17// RUN:   -analyzer-checker=core,security.cert.env.InvalidPtr       \18// RUN:   -verify=setenv,common                                     \19// RUN:   -DENV_INVALIDATING_CALL="setenv(\"X\", \"Y\", 0)"20//21// RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s     \22// RUN:   -analyzer-checker=core,security.cert.env.InvalidPtr       \23// RUN:   -verify=unsetenv,common                                   \24// RUN:   -DENV_INVALIDATING_CALL="unsetenv(\"X\")"25 26typedef int errno_t;27typedef char wchar_t;28 29int putenv(char *string);30errno_t _putenv_s(const char *varname, const char *value_string);31errno_t _wputenv_s(const wchar_t *varname, const wchar_t *value_string);32int setenv(const char *name, const char *value, int overwrite);33int unsetenv(const char *name);34 35void fn_without_body(char **e);36void fn_with_body(char **e) {}37 38void call_env_invalidating_fn(char **e) {39  ENV_INVALIDATING_CALL;40  // putenv-note@-1 5 {{'putenv' call may invalidate the environment parameter of 'main'}}41  // putenvs-note@-2 5 {{'_putenv_s' call may invalidate the environment parameter of 'main'}}42  // wputenvs-note@-3 5 {{'_wputenv_s' call may invalidate the environment parameter of 'main'}}43  // setenv-note@-4 5 {{'setenv' call may invalidate the environment parameter of 'main'}}44  // unsetenv-note@-5 5 {{'unsetenv' call may invalidate the environment parameter of 'main'}}45 46  *e;47  // common-warning@-1 {{dereferencing an invalid pointer}}48  // common-note@-2 {{dereferencing an invalid pointer}}49}50 51int main(int argc, char *argv[], char *envp[]) {52  char **e = envp;53  *e;    // no-warning54  e[0];  // no-warning55  *envp; // no-warning56  call_env_invalidating_fn(e);57  // common-note@-1 5 {{Calling 'call_env_invalidating_fn'}}58  // common-note@-2 4 {{Returning from 'call_env_invalidating_fn'}}59 60  *e;61  // common-warning@-1 {{dereferencing an invalid pointer}}62  // common-note@-2 {{dereferencing an invalid pointer}}63 64  *envp;65  // common-warning@-1 2 {{dereferencing an invalid pointer}}66  // common-note@-2 2 {{dereferencing an invalid pointer}}67 68  fn_without_body(e);69  // common-warning@-1 {{use of invalidated pointer 'e' in a function call}}70  // common-note@-2 {{use of invalidated pointer 'e' in a function call}}71 72  fn_with_body(e); // no-warning73}74