Coder Social home page Coder Social logo

Comments (16)

vladipus avatar vladipus commented on May 29, 2024

image
this implementation also seems off and risky, since the last argument is actually count that could be used as s1[count]

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Maybe something like that would do?
image

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Another problem is that strcpy_s guarantees null-termination, but your bound strings may be non-null terminated.

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Hmm, you are using strlen in you bounded string size method. That is strange and contradicts with my statement above. Now I see you have max_size + 1 as an array. But you still have to refactor the usage of strncpy

from mlib.

vladipus avatar vladipus commented on May 29, 2024

You can even end up with an invalid state since currently:
image

from mlib.

vladipus avatar vladipus commented on May 29, 2024

You could just
image
or maybe rewrite the m_core_strncpy to M_core_strncpy_s and use it everywhere afterwards.

from mlib.

vladipus avatar vladipus commented on May 29, 2024

image
this method is also implemented incorrectly. the size of the destination buffer can't be removed that simply and the m_core_strncat is also wrong in case of using strncat_s, semantically wrong.

from mlib.

vladipus avatar vladipus commented on May 29, 2024

An interesting thing. At least in debug build. The strncpy_s actually may write data past zero terminator, so it mast be saved manually and restored (for OOR compatibility.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 29, 2024

The issue with strncpy_s and strncat_s should be fixed in master.
This is strange however. All the tests already passed with Visual, and they did trigger this behavior of truncation...
So I don't know why they succeed...

this method is also implemented incorrectly. the size of the destination buffer can't be removed that simply

Which method?

from mlib.

P-p-H-d avatar P-p-H-d commented on May 29, 2024

This is strange however. All the tests already passed with Visual, and they did trigger this behavior of truncation...
So I don't know why they succeed...

It is because there was a constraint violation (as you notice), the default runtime handler is called which terminates the program and returns a negative error code to the caller! This is not handled by the script which assumes a successful termination. (It is fixed in master).

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Which method?
bounded string's equal str p

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Are you sure about your re-implementation? I've coped with the issue with _s variants. Seems like it is not that bad of an idea to use the secure methods on the bounded strings, since their size is statically defined.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 29, 2024

Which method?
bounded string's equal str p

I see no issue with _equal_str_p of bounded string.

Are you sure about your re-implementation?

As sure as the tests passed

from mlib.

vladipus avatar vladipus commented on May 29, 2024

I see no issue with _equal_str_p of bounded string.

In case you've also reimplemented the cat method yourself, there might be no issue. But there WAS one.

As sure as the tests passed

I've implemented _s variants through non-_s like so and all tests have also passed ;)
image

from mlib.

P-p-H-d avatar P-p-H-d commented on May 29, 2024

In case you've also reimplemented the cat method yourself, there might be no issue. But there WAS one.

Yes, the service that used the cat method was wrong. But _equal_str_p doesn't use this cat method :)

from mlib.

vladipus avatar vladipus commented on May 29, 2024

Maybe I've misrememeber =)
Ok, closing the issue.

from mlib.

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.