summaryrefslogtreecommitdiff
path: root/ext/I18N/Langinfo/Langinfo.xs
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-12-01 18:43:11 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-12-01 18:43:11 +0000
commitb27961e54c1afdd795823ec3e61ccca0718baf23 (patch)
tree1ce4bf6982b3fd7e0e7b9317914919d38e3d3aa4 /ext/I18N/Langinfo/Langinfo.xs
parent7c8d2b2109deeb6d2652b240018487f91c577a6c (diff)
downloadperl-b27961e54c1afdd795823ec3e61ccca0718baf23.tar.gz
Try to protect against wild langinfo() arguments.
p4raw-id: //depot/perl@13410
Diffstat (limited to 'ext/I18N/Langinfo/Langinfo.xs')
-rw-r--r--ext/I18N/Langinfo/Langinfo.xs28
1 files changed, 26 insertions, 2 deletions
diff --git a/ext/I18N/Langinfo/Langinfo.xs b/ext/I18N/Langinfo/Langinfo.xs
index d335eec71e..314e8918b3 100644
--- a/ext/I18N/Langinfo/Langinfo.xs
+++ b/ext/I18N/Langinfo/Langinfo.xs
@@ -19,8 +19,32 @@ langinfo(code)
int code
CODE:
#ifdef HAS_NL_LANGINFO
- char *s = nl_langinfo(code);
- RETVAL = newSVpvn(s, strlen(s));
+ char *s;
+ if (code) { /* bold assumption: all valid langinfo codes > 0 */
+#ifdef _MAXSTRMSG
+ if (code >= _MAXSTRMSG
+ RETVAL = &PL_sv_undef;
+ else
+#else
+# ifdef _NL_NUM_ITEMS
+ if (code >= _NL_NUM_ITEMS)
+ RETVAL = &PL_sv_undef;
+ else
+# else
+# ifdef _NL_NUM
+ if (code >= _NL_NUM)
+ RETVAL = &PL_sv_undef;
+ else
+# endif
+# endif
+#endif
+ {
+ s = nl_langinfo(code);
+ RETVAL = newSVpvn(s, strlen(s));
+ }
+ } else {
+ RETVAL = &PL_sv_undef;
+ }
#else
croak("nl_langinfo() not implemented on this architecture");
#endif