aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2017-09-30 17:14:34 +0100
committerSimon McVittie <smcv@debian.org>2017-10-01 13:21:56 +0100
commitcf7df018ccf5513b79bcfe0b108e348b6da341c1 (patch)
treeeb8a8ebf31abec4ccde14aa97f28ca314ef5f044
parent14344f58f08b6868daf7f80eab1b12682f3740f0 (diff)
downloadikiwiki-cf7df018ccf5513b79bcfe0b108e348b6da341c1.tar
ikiwiki-cf7df018ccf5513b79bcfe0b108e348b6da341c1.tar.gz
IkiWiki::Receive: Avoid using asprintf
On GNU/Linux, it isn't declared in stdio.h unless we define _GNU_SOURCE, which we don't; using the implicit declaration risks crashes on platforms where sizeof(pointer) != sizeof(int). On other platforms it isn't guaranteed to exist at all. Signed-off-by: Simon McVittie <smcv@debian.org>
-rw-r--r--IkiWiki/Receive.pm6
1 files changed, 4 insertions, 2 deletions
diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm
index 332ba7c2c..f985f560b 100644
--- a/IkiWiki/Receive.pm
+++ b/IkiWiki/Receive.pm
@@ -26,6 +26,8 @@ sub genwrapper () {
my $ret=<<"EOF";
{
int u=getuid();
+ /* 3 characters per byte is certainly enough */
+ char uid_string[sizeof(u) * 3 + 1];
EOF
$ret.="\t\tif ( ".
join("&&", map {
@@ -46,8 +48,8 @@ EOF
while (read(0, &buf, 256) != 0) {}
exit(0);
}
- asprintf(&s, "%i", u);
- addenv("CALLER_UID", s);
+ snprintf(uid_string, sizeof(uid_string), "%i", u);
+ addenv("CALLER_UID", uid_string);
}
EOF
return $ret;