Ticket #3255 (new bug)

Opened 6 months ago

Last modified 6 months ago

malformed unix socket filename

Reported by: kaliber Owned by: bonefish
Priority: normal Milestone: R1
Component: Network & Internet Version: R1 development
Cc: Blocked By:
Platform: All Blocking:

Description

Attached code creates 'socket_test_filenam\302K\200\C' instead of 'socket_test_filename'. It works on linux.

gcc socket.c -lnetwork

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define SOCK_PATH "socket_test_filename"

int main(void)
{
    int s, len;
    struct sockaddr_un local;
    char str[100];

    if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
        perror("socket");
        exit(1);
    }

    local.sun_family = AF_UNIX;
    strcpy(local.sun_path, SOCK_PATH);
    unlink(local.sun_path);
    len = strlen(local.sun_path) + sizeof(local.sun_family);
    if (bind(s, (struct sockaddr *)&local, len) == -1) {
        perror("bind");
        exit(1);
    }
    return 0;
}



Change History

Changed 6 months ago by axeld

  • status changed from new to closed
  • resolution set to invalid

The code is incorrect anyway, as you make assumptions about the contents of sockaddr_un - on Haiku, it also has a length field that you miss on the length computation, causing the terminating null byte to be cut off.

Please always just use sizeof(sockaddr_un) for the length.

Changed 6 months ago by kaliber

  • status changed from closed to reopened
  • resolution invalid deleted

Oh, my mistake, sorry. The correct length should be: len = offsetof(struct sockaddr_un, sun_path) + strlen(local.sun_path)

But seems there is a bug in haiku too. Here is more information: http://bugs.freedesktop.org/show_bug.cgi?id=19445

Changed 6 months ago by axeld

  • owner changed from axeld to bonefish
  • status changed from reopened to new
  • component changed from - General to Network & Internet

Indeed, that looks like a bug, thanks for the note and persistence! :-) BTW it's called "Haiku", not "HaikuOS".

Note: See TracTickets for help on using tickets.