From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3325 invoked from network); 17 Aug 2022 10:05:18 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 17 Aug 2022 10:05:18 -0000 Received: (qmail 13622 invoked by uid 550); 17 Aug 2022 10:05:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 12215 invoked from network); 16 Aug 2022 18:33:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=s6.eternalimpact.info; s=mail; t=1660674816; bh=Q7CL9sG+2dJo9YcxjZvRLxDw0f7tCK4MqjbKEOgQ/WI=; h=Date:To:From:Subject:From; b=Q/7Mx/T5ubGGJ10ZzcQi1zwPbeR7ClmTp3CkImPjQ3CmMuyTwTl5yRXCoVqs+Mon3 jTCZSUepXO7EfvQ6+FN1gQfvDQ4hS2+94eO9i4ACPxH9rGOiiLIYATmsutTolMAGz4 KHDGeV7vQVA1x4d6/bqFCpumghLuTlJ59KzfKGtL9phQYTVBlNuXXPTEW0tgSvHAws GrZMxRhmgFDnlRMuW41MbaFxiZ1e7rBFAmQcptN++4SJVqzoVcbB9WmKTDxhOsmSUC GjBPKriDGwt+egZYTQfsGZExOpQJP3nfTELNo2p2y0GP/g4PAqC6b5aCXLdQ22SVj+ FIjw/wG4AXeew== Date: Tue, 16 Aug 2022 18:33:35 +0000 To: musl@lists.openwall.com From: Anonymousemail Message-ID: <6bac31d90ea71e6151f950f1cc5e6171@anonymousemail.me> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="b1_VXDDF30ghnnmYm7xNBBnahj3dgngWwILspEKwyRsM" Content-Transfer-Encoding: 8bit Subject: [musl] Broken freopen() does not reset fwide() This is a multi-part message in MIME format. --b1_VXDDF30ghnnmYm7xNBBnahj3dgngWwILspEKwyRsM Content-Type: text/plain; charset=us-ascii I'm using musl based distribution. The official example from https://en.cppreference.com/w/c/io/fwide is malfunctioning, musl does not reset the fwide(), returns -1 (meaning BYTE oriented). Output from example on musl: 1) A newly opened stream has no orientation.     no orientation 2) Establish byte orientation.     narrow orientation     narrow character read '#'     wide character read 'i' 3) Only freopen() can reset stream orientation. 4) A reopened stream has no orientation.     narrow orientation  <- problem detected here, should say "no orientation" 5) Establish wide orientation.     narrow orientation     narrow character read '#'     wide character read 'i' Another simple example to reproduce the issue.: #include <stdio.h> #include <wchar.h> #include <stdlib.h> // for EXIT_SUCCESS #include <assert.h> int main() {     enum { narrow = -1, query = 0, wide = 1 };     FILE* test = fopen("test.bin", "r");     if(!test) {         puts("You need to have test.bin file.");         abort();     }     // establish NARROW orientation     fwide(test, narrow);     // reopen to reset, broken on musl     freopen("test.bin", "r", test);     assert(fwide(test, query) == 0); // will fail on musl     // CLEANUP     fclose(test);     // Exit the program     return EXIT_SUCCESS; } ----- Save as main.c, run with cc main.c echo test >test.bin ./a.out Will output Assertion failed: fwide(test, query) == 0 (main2.c: main: 17) Aborted   --b1_VXDDF30ghnnmYm7xNBBnahj3dgngWwILspEKwyRsM Content-Type: text/html; charset=us-ascii

Powered by Anonymousemail → Join Us!

I'm using musl based distribution.
The official example from https://en.cppreference.com/w/c/io/fwide is malfunctioning, musl does not reset the fwide(), returns -1 (meaning BYTE oriented).

Output from example on musl:
1) A newly opened stream has no orientation.
    no orientation
2) Establish byte orientation.
    narrow orientation
    narrow character read '#'
    wide character read 'i'
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
    narrow orientation  <- problem detected here, should say "no orientation"
5) Establish wide orientation.
    narrow orientation
    narrow character read '#'
    wide character read 'i'

Another simple example to reproduce the issue.:
#include <stdio.h>
#include <wchar.h>
#include <stdlib.h> // for EXIT_SUCCESS
#include <assert.h>

int main() {
    enum { narrow = -1, query = 0, wide = 1 };
    FILE* test = fopen("test.bin", "r");
    if(!test) {
        puts("You need to have test.bin file.");
        abort();
    }
    // establish NARROW orientation
    fwide(test, narrow);
    // reopen to reset, broken on musl
    freopen("test.bin", "r", test);
    assert(fwide(test, query) == 0); // will fail on musl
    // CLEANUP
    fclose(test);
    // Exit the program
    return EXIT_SUCCESS;
}

-----
Save as main.c, run with
cc main.c
echo test >test.bin
./a.out

Will output
Assertion failed: fwide(test, query) == 0 (main2.c: main: 17)
Aborted
  --b1_VXDDF30ghnnmYm7xNBBnahj3dgngWwILspEKwyRsM--