Giter VIP home page Giter VIP logo

smallchat's People

Contributors

antirez avatar ekkosun avatar eltociear avatar how2051 avatar juniorohanyere avatar pauloxnet avatar zhangkai803 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smallchat's Issues

Unsafe use of return value of snprintf

Unsafe use of return value of snprintf on line 346 can result in out of bounds read when length of nickname + length of name > 254.
https://github.com/antirez/smallchat/blob/main/smallchat.c#L346

from https://linux.die.net/man/3/snprintf
If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available

Could fix by bounding msglen variable to a max value of 256.

There is a bug in finding the maximum slot

In line 105 of smallchat-server.c, it should be wrapped in a pair of curly braces. Because the break on line 106 will now exit the loop directly.

    if (Chat->maxclient == c->fd) {
        /* Ooops, this was the max client set. Let's find what is
         * the new highest slot used. */
        int j;
        for (j = Chat->maxclient-1; j >= 0; j--) {
            if (Chat->clients[j] != NULL) Chat->maxclient = j;
            break;
        }
        if (j == -1) Chat->maxclient = -1; // We no longer have clients.
    }

should be changed to

    if (Chat->maxclient == c->fd) {
        /* Ooops, this was the max client set. Let's find what is
         * the new highest slot used. */
        int j;
        for (j = Chat->maxclient - 1; j >= 0; j--) {
            if (Chat->clients[j] != NULL) {
                Chat->maxclient = j;
                break;
            }
        }
        if (j == -1) Chat->maxclient = -1; // We no longer have clients.
    }

How can it compile on windows?

Thanks for your project. It is very nice for junior developers to learn network and C programming.One more question I think it is better if the "smallchat" can run or compile on windows. Because most of our junior developers program on windows ^_^!

anyone can provide python implementations?

I watched the video mentioned in the repo. I want to know his specific principles and philosophy of the code. Can anyone provide a python implementation of the code?

documentation

Brother, is there any usage documentation for this or how to deploy it?

About Performance and Testing

In addition to functional code, testing, especially performance testing is also the point I want to learn about. For example, how much impact does concurrency and delay have on the program?

Mastering performance testing methods helps me quantitatively understand why write this way.

why set j to readfds not client[j].fd?

for (int j = 0; j <= Chat->maxclient; j++) {
    if (Chat->clients[j]) FD_SET(j, &readfds);
}

why set FD_SET(j, &readfds); not FD_SET(Chat->clients[j].fd, &readfds);?

chatMalloc and chatRealloc will probably never fail on Linux, even if memory is full

void *chatMalloc(size_t size) {

Depending on the configuration of someone's system, Linux will probably over-commit and not make malloc/realloc return a NULL pointer even if memory is full.

The default behavior is to over-commit if the memory request is not "unreasonable". Which basically means any small memory allocation request will return a pointer as if it allocated successfully, but then the program will segfault when trying to write to it, or more likely be killed by the out of memory manager before a write to it is attempted.

There's not really a great platform-independent solution, but I usually read /proc/meminfo and check the CommitLimit to check if an allocation request is too large. Edit: For this particular case, probably best to use MemAvailable

What about add an open-source license

Hi, @antirez.

smallchat is an awesome project. I learned a lot from it.

What about add an exact open-source license to this repo?
I think this will allow people to better learn and participate in this interesting program.

Regards,
Xinfeng

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.