]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
IkiWiki::Receive: Avoid using asprintf
authorSimon McVittie <smcv@debian.org>
Sat, 30 Sep 2017 16:14:34 +0000 (17:14 +0100)
committerSimon McVittie <smcv@debian.org>
Sun, 1 Oct 2017 12:21:56 +0000 (13:21 +0100)
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>
IkiWiki/Receive.pm

index 332ba7c2c378d45123c915115c243379940e9bbf..f985f560b3d17b38aeef783a3b0ccbd0960d034d 100644 (file)
@@ -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;