Coder Social home page Coder Social logo

Comments (6)

dankamongmen avatar dankamongmen commented on June 10, 2024

ISO/IEC 9899:1999 (E) 7.24.6.3.2 "The mbrtowc function" seems unclear on this.

It would surprise me if people implemented it that way, as it contradicts expectations for e.g. strncmp() or strncpy() (i.e. your YMM example is AFAICT invalid for strncmp(), but maybe not?).

Fixing this isn't hard, though it will introduce a bit of complexity and nastiness in this very core function.

Let's take a look at the common implementations.

from notcurses.

mulle-nat avatar mulle-nat commented on June 10, 2024

You are right. If interpreted as akin to strncmp, it shouldn't be a problem. But because you can also give it invalid multibyte sequences and its supposed to return error values, I was under the impression n is more a buffer length kinda parameter. I hardly ever use wchar_t, so apologies, if this is a red herring.

from notcurses.

dankamongmen avatar dankamongmen commented on June 10, 2024

no, i appreciate filing the bug. i am not certain of my interpretation, and have wondered about this before (it also came up in a bug filed by @zhiayang a few weeks ago). we might end up naturally enforcing this as part of handling that request.

from notcurses.

dankamongmen avatar dankamongmen commented on June 10, 2024

here's an interesting link https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level#2__better_fortification_coverage

One example is wcrtomb, where glibc makes stronger assumptions about the object size passed than POSIX allowed. Specifically, glibc assumes that the buffer passed to wcrtomb is always at least MB_CUR_MAX bytes long. In contrast, the POSIX description makes no such assumption. Due to this discrepancy, any application that passed a smaller buffer would potentially make wcrtomb overflow the buffer during conversion. Then the fortified version __wcrtomb_chk aborts with a buffer overflow, expecting a buffer that is MB_CUR_MAX bytes long. We fixed this bug in glibc-2.36 by making glibc conform to POSIX .

from notcurses.

mulle-nat avatar mulle-nat commented on June 10, 2024

I read this as that mbrtowc(&wc, gcluster, MB_LEN_MAX, &mbt); used to be fine, but now is wrong or ?

from notcurses.

dankamongmen avatar dankamongmen commented on June 10, 2024

I read this as that mbrtowc(&wc, gcluster, MB_LEN_MAX, &mbt); used to be fine, but now is wrong or ?

nah, it was an error in the implementation of wcrtomb() in glibc. just an interesting datum.

i think the Standard is fundamentally ambiguous here. i'd still like to go look at implementations, though that guarantees nothing about the future (your YMM example is very much the kind of thing i'm worried about).

from notcurses.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.