From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13758 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Keyhan Vakil Newsgroups: gmane.linux.lib.musl.general Subject: Bug in gets function? Date: Mon, 11 Feb 2019 18:55:24 -0800 Message-ID: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="129716"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-13774-gllmg-musl=m.gmane.org@lists.openwall.com Tue Feb 12 03:55:39 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1gtOEV-000XfH-RL for gllmg-musl@m.gmane.org; Tue, 12 Feb 2019 03:55:39 +0100 Original-Received: (qmail 32389 invoked by uid 550); 12 Feb 2019 02:55:37 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32355 invoked from network); 12 Feb 2019 02:55:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkeley-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=VdlLFfVax66z7EwcH0ndCE4aL90UXrxCc1fxA6IKkmM=; b=UGRpMN9Vkl5492JQzYvciKVId9g6a9XfY1yozp4YSaQBVk+priEDjbVpGk157X96Lx qGex1il8+phZ/Mi3aRWpperwV+zWP3iTYBiULAcQUHzaRJ61GOa2unfIyRDhniFAmJAg h0i09rKICl37GNZ9VZFSXmj70+8GPugrbrmGKphodD6XQ2WbFsYr3qn62JMQWX8vrwDd w4TGqoQEsyskriUkZSASvbsMtqO74HwIx/19IFv974c6e4PJ9m8ZjahnkQVylByfszmW sevXvgseTSxSCXSiQXWv1HqcC8JzG/2ASFFM0L4voNYLi/TJ2BvJvysBSIKnu6RcUNul Xupw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=VdlLFfVax66z7EwcH0ndCE4aL90UXrxCc1fxA6IKkmM=; b=ZNFAfS8hwAnJnm/le6VdWKHnsn4EtsNrc14hlTKrt26QMQ11kkTTxCAjgSyiwjKwtP oPBiVvKCZ38lkGTouMLb5wZSxcgcPP0h7ruKyEqOIMoIuVi4x7M3z7SLVxCHtSTOPtHv +vcK42XN/XYLVf8+FG0qHWQQ2jpm/ElrW3iA42XlvvMkFmSwYKZ7EpESzlOJwGc418St 83CVWiIs+qk1bPIZcYNNWQ3JC68+Pwz0xiJgl4iznojdvKlU+o4efo9tJoWOwJj0+YEf MGYBn5oKCjuGJmcLdgRLfQeY/SlI6E/dL5L3d4X3tx6dDI1XQMrsxoPPoLnFZJRpcuWN UReQ== X-Gm-Message-State: AHQUAubo8MajDt95FA3it5jhctDttdrC+jBlwaamQLEjxRO2oNi9qjzD 5hId1LjS7YQOfAkvs+MAtAJWO7TH4mDGBBXVRooZpwCP X-Google-Smtp-Source: AHgI3IaQJDY/4JaZAeimbJzZra2PX6tgBlNO9O3B4hbr/nf2lX2Eb+W1X1RLz0TGg6+yiQlgdbwB+1CzUBFn4Yvq19s= X-Received: by 2002:a02:660e:: with SMTP id k14mr134584jac.34.1549940124988; Mon, 11 Feb 2019 18:55:24 -0800 (PST) Xref: news.gmane.org gmane.linux.lib.musl.general:13758 Archived-At: Hi. It seems that the gets function does not follow the C99 spec. In particular, if the input contains a null byte in the middle of the input, then the new-line character is not discarded. For reference, here's the relevant part in the C99 standard (7.19.7.7): > The gets function reads characters from the input stream pointed to > by stdin, into the array pointed to by s, until end-of-=EF=AC=81le is > encountered or a new-line character is read. Any new-line character > is discarded, and a null character is written immediately after the > last character read into the array. Here is an example: #include char s[8]; int main() { gets(s); for (int i =3D 0; i < sizeof s; i++) { printf("%02x ", s[i]); } printf("\n"); return 0; } When compiled against gcc: $ echo -e 'A\x00B' | ./a.out 41 00 42 00 00 00 00 00 When compiled against musl: $ echo -e 'A\x00B' | ./a.out 41 00 42 0a 00 00 00 00 Note the terminating newline, which contradicts the spec. Thanks, Keyhan