-
Notifications
You must be signed in to change notification settings - Fork 580
replace various sv_catpv(sv,"cstr") calls with len counted calls #22652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blead
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5320,7 +5320,7 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state, | |
|
||
substitute_parse = newSVpvs("?:"); | ||
sv_catsv(substitute_parse, value_sv); | ||
sv_catpv(substitute_parse, ")"); | ||
sv_catpvs(substitute_parse, ")"); | ||
|
||
/* The value should already be native, so no need to convert on EBCDIC | ||
* platforms.*/ | ||
|
@@ -10752,7 +10752,8 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth, | |
} | ||
first_time = FALSE; | ||
|
||
sv_catpv(substitute_parse, SvPVX(this_sequence)); | ||
sv_catpvn(substitute_parse, | ||
SvPVX(this_sequence), SvCUR(this_sequence)); | ||
} | ||
} | ||
} | ||
|
@@ -14222,7 +14223,6 @@ S_handle_user_defined_property(pTHX_ | |
|
||
const char * s0 = string; /* Points to first byte in the current line | ||
being parsed in 'string' */ | ||
const char overflow_msg[] = "Code point too large in \""; | ||
SV* running_definition = NULL; | ||
|
||
PERL_ARGS_ASSERT_HANDLE_USER_DEFINED_PROPERTY; | ||
|
@@ -14279,7 +14279,7 @@ S_handle_user_defined_property(pTHX_ | |
s = e; | ||
} | ||
if (SvCUR(msg) > 0) sv_catpvs(msg, "; "); | ||
sv_catpv(msg, overflow_msg); | ||
sv_catpvs(msg, "Code point too large in \""); | ||
Perl_sv_catpvf(aTHX_ msg, "%" UTF8f, | ||
UTF8fARG(is_contents_utf8, s - s0, s0)); | ||
sv_catpvs(msg, "\""); | ||
|
@@ -14314,7 +14314,7 @@ S_handle_user_defined_property(pTHX_ | |
s = e; | ||
} | ||
if (SvCUR(msg) > 0) sv_catpvs(msg, "; "); | ||
sv_catpv(msg, overflow_msg); | ||
sv_catpvs(msg, "Code point too large in \""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I object to taking a common value and making it into duplicate copies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think overflow_msg could be changed to a define, and then this code could use the define. Alternatively cant these cases use sv_catpvn() and use sizeof on the constant string (or do i misremember that that works). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code as written, prohibits de-duping identical RO string C literals. CC LTO can do some tricks, usually static failed to inline FNs, but moment you do "&" on a static fns, and static const char arrays, %99 chance, & of will be done on a static const char array, and that ptr to static gets passed to another FN, therefore LTO de-duping is not possible.
in Makes more sense in the world of closed source, commercial .o files than FOSS world. For example instead |
||
Perl_sv_catpvf(aTHX_ msg, "%" UTF8f, | ||
UTF8fARG(is_contents_utf8, s - s0, s0)); | ||
sv_catpvs(msg, "\""); | ||
|
@@ -15929,12 +15929,17 @@ S_parse_uniprop_string(pTHX_ | |
|
||
append_name_to_msg: | ||
{ | ||
const char * prefix = (runtime && level == 0) ? " \\p{" : " \""; | ||
const char * suffix = (runtime && level == 0) ? "}" : "\""; | ||
bool is_root = runtime && level == 0; | ||
const char * prefix = is_root ? " \\p{" : " \""; | ||
Size_t prefixl = is_root ? STRLENs(" \\p{") : STRLENs(" \""); | ||
const char * suffix; | ||
Size_t suffixl; | ||
|
||
sv_catpv(msg, prefix); | ||
sv_catpvn(msg, prefix, prefixl); | ||
Perl_sv_catpvf(aTHX_ msg, "%" UTF8f, UTF8fARG(is_utf8, name_len, name)); | ||
sv_catpv(msg, suffix); | ||
suffix = is_root ? "}" : "\""; | ||
suffixl = is_root ? STRLENs("}") : STRLENs("\""); | ||
sv_catpvn(msg, suffix, suffixl); | ||
} | ||
|
||
return NULL; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this done better with
sv_catsv
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Leont I am not so sure. This code is effectively using AV's and SV's for their "self cleanup" properties. As far as I could see these are "normal" SVPV's constructed by the regex compiler, and as such use sv_catpv() would just do a bunch of checks we know will be false. This is one of the few cases where using SvPVX() makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never know looking at interp code, if
sv_catpv(substitute_parse, SvPVX(this_sequence));
is code rot, or a security/exploit fix or a unicode bug.I have near future plans to add a "OPV" or "PVR" or "CST" or "PVO" or pascal string object/class/api to macro away/automate away all the redundant Newx() SAVEFREEPV() code and K&R "string objects" core is gather over time. Sane src code symbols/identifiers/packages don't exceed 1 console line. console format warnings dont go above 80*3. 128 bytes or 256 bytes on C stack then OOM croak is good enough. Perl outputs that don't accept varlen user input strings can't overflow from accidents.
(84c133a#diff-d481115f10d65d6967e0a678eb02cc6ccd14c19446926320ff697b15caef7ffaR2114)
Least used feature in Perl C, then and right now. but svf256 looks like a security feature against abuse long console strings. But perl already wont SEGV (i hope) with a 5.5 GB file path in a SVPV *..
What happened to Mr Mortal? was he too violent to lead XS clan and finally he was eliminated [unfinished joke]? SAVEFREEPV is trending now.