Skip Menu |

This queue is for tickets about the BSD-Sysctl CPAN distribution.

Report information
The Basics
Id: 70803
Status: open
Priority: 0/
Queue: BSD-Sysctl

People
Owner: Nobody in particular
Requestors: bgp4 [...] rambler.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: \0 at the end of string sysctls
Tere is off by one error for string sysctl - \0 added at end of line. Test script: use BSD::Sysctl 'sysctl'; say sysctl('hw.machine'); :~> ./sysctl.pl | hd 00000000 61 6d 64 36 34 00 0a |amd64..| 00000007 Versions: p5-BSD-Sysctl-0.10 :~> uname -srp FreeBSD 8.2-PRERELEASE-20101227 amd64 perl v5.14.1
This is regression - in version 0.08 there is no \0 at end of line
On Thu Sep 08 05:45:47 2011, https://id.rambler.ru/users/bgp4 wrote: Show quoted text
> Tere is off by one error for string sysctl - \0 added at end of line. > > Test script:
Or more precisely: david@profane:~% sysctl -n hw.machine | hd 00000000 69 33 38 36 0a |i386.| 00000005 david@profane:~% perl -MBSD::Sysctl=sysctl -le 'print sysctl("hw.machine")' |hd 00000000 69 33 38 36 00 0a |i386..| 00000006 Which indeed sucks. Thanks for the report, I'll look into it. David
Patch with proposed fix is attached
Subject: patch-Sysctl.xs
--- Sysctl.xs.orig 2011-09-08 13:17:32.000000000 +0000 +++ Sysctl.xs 2011-09-08 13:19:28.000000000 +0000 @@ -393,7 +393,7 @@ switch(oid_fmt) { case FMT_A: SvPOK_on(sv_buf); - SvCUR_set(sv_buf, buflen); + SvCUR_set(sv_buf, strnlen(buf, buflen)); RETVAL = sv_buf; break; case FMT_INT:
On Thu Sep 08 09:23:22 2011, https://id.rambler.ru/users/bgp4 wrote: Show quoted text
> Patch with proposed fix is attached
wow, as simple as that? Currently migrating my repo to github. Once its tidied up I'll bring this onboard and kick out a new release. Thanks a million, David
Чтв Сен 08 09:23:22 2011, https://id.rambler.ru/users/bgp4 писал: Show quoted text
> Patch with proposed fix is attached
strnlen() not available in old FreeBSD versions, patch incomplete...
Show quoted text
> strnlen() not available in old FreeBSD versions, patch incomplete...
A bit better patch. (buflen - 1) currently work, but it is not documented, that string returned by sysctl(3) is null terminated and strnlen(3) is more robust - it will work for not terminated strings.
Subject: patch-Sysctl.xs
--- Sysctl.xs.orig 2009-09-25 19:50:50.000000000 +0000 +++ Sysctl.xs 2011-09-09 06:16:50.000000000 +0000 @@ -42,8 +42,10 @@ #include <netinet/ip_var.h> #include <netinet/udp.h> #include <netinet/udp_var.h> - #include <netinet6/raw_ip6.h> + +#include <string.h> + #include "bsd-sysctl.h" int @@ -393,7 +395,11 @@ switch(oid_fmt) { case FMT_A: SvPOK_on(sv_buf); - SvCUR_set(sv_buf, buflen); +#if __FreeBSD_version < 800067 + SvCUR_set(sv_buf, buflen - 1); +#else + SvCUR_set(sv_buf, strnlen(buf, buflen)); +#endif RETVAL = sv_buf; break; case FMT_INT: