Skip to content

Commit

Permalink
Fix crashing when calling warn() and croak() functions
Browse files Browse the repository at this point in the history
Functions warn() and croak() take first parameter printf-like format.
Arbitrary string can cause perl crash when contains one or more '%'.

Format "%s" should be used to pass abitrary string parameter.
  • Loading branch information
pali committed Feb 14, 2017
1 parent e6656c4 commit c6d410d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions DBI.xs
Expand Up @@ -85,10 +85,10 @@ extern Pid_t getpid (void);
#endif

#ifndef warn_sv
static void warn_sv(SV *sv) { dTHX; warn(SvPV_nolen(sv)); }
static void warn_sv(SV *sv) { dTHX; warn("%s", SvPV_nolen(sv)); }
#endif
#ifndef croak_sv
static void croak_sv(SV *sv) { dTHX; croak(SvPV_nolen(sv)); }
static void croak_sv(SV *sv) { dTHX; croak("%s", SvPV_nolen(sv)); }
#endif

/* types of method name */
Expand Down Expand Up @@ -494,7 +494,7 @@ _join_hash_sorted(HV *hash, char *kv_sep, STRLEN kv_sep_len, char *pair_sep, STR

/* handy for embedding into condition expression for debugging */
/*
static int warn1(char *s) { warn(s); return 1; }
static int warn1(char *s) { warn("%s", s); return 1; }
static int dump1(SV *sv) { dTHX; sv_dump(sv); return 1; }
*/

Expand Down
2 changes: 1 addition & 1 deletion dbipport.h
Expand Up @@ -4794,7 +4794,7 @@ DPPP_(my_eval_pv)(char *p, I32 croak_on_error)
PUTBACK;

if (croak_on_error && SvTRUE(GvSV(errgv)))
croak(SvPVx(GvSV(errgv), na));
croak("%s", SvPVx(GvSV(errgv), na));

return sv;
}
Expand Down

0 comments on commit c6d410d

Please sign in to comment.