summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-06-02 07:16:10 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-06-02 07:16:10 +0000
commiteff96b52edf00b5721cd2c3b90d509f4653dd1be (patch)
tree6500a4b22d4836304ac356ac48541a8e24df8018
parent20ce7b12268a3d32b5b246928de5084322e709cf (diff)
downloadperl-eff96b52edf00b5721cd2c3b90d509f4653dd1be.tar.gz
avoid dereferencing null pointer from getpwent() et al
p4raw-id: //depot/perl@3519
-rw-r--r--pp_sys.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/pp_sys.c b/pp_sys.c
index dd588ec173..054645e33b 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4556,7 +4556,7 @@ PP(pp_gpwent)
struct passwd *pwent;
STRLEN n_a;
#ifdef HAS_GETSPENT
- struct spwd *spwent;
+ struct spwd *spwent = NULL;
#endif
if (which == OP_GPWNAM)
@@ -4567,14 +4567,18 @@ PP(pp_gpwent)
pwent = (struct passwd *)getpwent();
#ifdef HAS_GETSPNAM
- if (which == OP_GPWNAM)
- spwent = getspnam(pwent->pw_name);
+ if (which == OP_GPWNAM) {
+ if (pwent)
+ spwent = getspnam(pwent->pw_name);
+ }
# ifdef HAS_GETSPUID /* AFAIK there isn't any anywhere. --jhi */
- else if (which == OP_GPWUID)
- spwent = getspnam(pwent->pw_name);
+ else if (which == OP_GPWUID) {
+ if (pwent)
+ spwent = getspnam(pwent->pw_name);
+ }
# endif
- else
- spwent = (struct spwd *)getspent();
+ else
+ spwent = (struct spwd *)getspent();
#endif
EXTEND(SP, 10);