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>
master
Simon McVittie 2017-09-30 17:14:34 +01:00
parent 14344f58f0
commit cf7df018cc
1 changed files with 4 additions and 2 deletions

View File

@ -26,6 +26,8 @@ sub genwrapper () {
my $ret=<<"EOF"; my $ret=<<"EOF";
{ {
int u=getuid(); int u=getuid();
/* 3 characters per byte is certainly enough */
char uid_string[sizeof(u) * 3 + 1];
EOF EOF
$ret.="\t\tif ( ". $ret.="\t\tif ( ".
join("&&", map { join("&&", map {
@ -46,8 +48,8 @@ EOF
while (read(0, &buf, 256) != 0) {} while (read(0, &buf, 256) != 0) {}
exit(0); exit(0);
} }
asprintf(&s, "%i", u); snprintf(uid_string, sizeof(uid_string), "%i", u);
addenv("CALLER_UID", s); addenv("CALLER_UID", uid_string);
} }
EOF EOF
return $ret; return $ret;