Project

General

Profile

Backport #7775 ยป sockaddr-ignore-truncated-r38993-to-193.patch

akr (Akira Tanaka), 02/03/2013 09:04 PM

View differences:

ext/socket/basicsocket.c (working copy)
358 358
{
359 359
    struct sockaddr_storage buf;
360 360
    socklen_t len = (socklen_t)sizeof buf;
361
    socklen_t len0 = len;
361 362
    rb_io_t *fptr;
362 363

  
363 364
    GetOpenFile(sock, fptr);
364 365
    if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
365 366
	rb_sys_fail("getsockname(2)");
367
    if (len0 < len) len = len0;
366 368
    return rb_str_new((char*)&buf, len);
367 369
}
368 370

  
......
387 389
{
388 390
    struct sockaddr_storage buf;
389 391
    socklen_t len = (socklen_t)sizeof buf;
392
    socklen_t len0 = len;
390 393
    rb_io_t *fptr;
391 394

  
392 395
    GetOpenFile(sock, fptr);
393 396
    if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
394 397
	rb_sys_fail("getpeername(2)");
398
    if (len0 < len) len = len0;
395 399
    return rb_str_new((char*)&buf, len);
396 400
}
397 401

  
......
475 479
{
476 480
    struct sockaddr_storage buf;
477 481
    socklen_t len = (socklen_t)sizeof buf;
482
    socklen_t len0 = len;
478 483
    rb_io_t *fptr;
479 484

  
480 485
    GetOpenFile(sock, fptr);
481 486
    if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
482 487
	rb_sys_fail("getsockname(2)");
488
    if (len0 < len) len = len0;
483 489
    return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
484 490
}
485 491

  
......
507 513
{
508 514
    struct sockaddr_storage buf;
509 515
    socklen_t len = (socklen_t)sizeof buf;
516
    socklen_t len0 = len;
510 517
    rb_io_t *fptr;
511 518

  
512 519
    GetOpenFile(sock, fptr);
513 520
    if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
514 521
	rb_sys_fail("getpeername(2)");
522
    if (len0 < len) len = len0;
515 523
    return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
516 524
}
517 525

  
ext/socket/unixsocket.c (working copy)
116 116
    if (NIL_P(fptr->pathv)) {
117 117
	struct sockaddr_un addr;
118 118
	socklen_t len = (socklen_t)sizeof(addr);
119
	socklen_t len0 = len;
119 120
	if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
120 121
	    rb_sys_fail(0);
122
        if (len0 < len) len = len0;
121 123
	fptr->pathv = rb_obj_freeze(rb_str_new_cstr(rsock_unixpath(&addr, len)));
122 124
    }
123 125
    return rb_str_dup(fptr->pathv);
......
445 447
    rb_io_t *fptr;
446 448
    struct sockaddr_un addr;
447 449
    socklen_t len = (socklen_t)sizeof addr;
450
    socklen_t len0 = len;
448 451

  
449 452
    GetOpenFile(sock, fptr);
450 453

  
451 454
    if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
452 455
	rb_sys_fail("getpeername(2)");
456
    if (len0 < len) len = len0;
453 457
    return rsock_unixaddr(&addr, len);
454 458
}
455 459

  
ext/socket/init.c (working copy)
448 448
rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
449 449
{
450 450
    int fd2;
451
    socklen_t len0 = len ? *len : 0;
451 452

  
452 453
    rb_secure(3);
453 454
    rb_io_set_nonblock(fptr);
......
466 467
	}
467 468
        rb_sys_fail("accept(2)");
468 469
    }
470
    if (len && len0 < *len) *len = len0;
469 471
    rb_update_max_fd(fd2);
470 472
    make_fd_nonblock(fd2);
471 473
    return rsock_init_sock(rb_obj_alloc(klass), fd2);
......
481 483
accept_blocking(void *data)
482 484
{
483 485
    struct accept_arg *arg = data;
484
    return (VALUE)accept(arg->fd, arg->sockaddr, arg->len);
486
    int ret;
487
    socklen_t len0 = 0;
488
    if (arg->len) len0 = *arg->len;
489
    ret = accept(arg->fd, arg->sockaddr, arg->len);
490
    if (arg->len && len0 < *arg->len) *arg->len = len0;
491
    return (VALUE)ret;
485 492
}
486 493

  
487 494
VALUE