[Bug 276809] SEGFAULTs using libjail

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 03 Feb 2024 17:53:03 UTC

            Bug ID: 276809
           Summary: SEGFAULTs using libjail
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: freebsd-bugs@aliases.systohc.net

I'm constantly getting SEGFAULTs using libjail from C as well as from Python.
Is it my fault or am I triggering a bug?

=== listjailparams.c ===
#include <stdio.h>
#include <jail.h>

int main(int argc, char *argv[])
        struct jailparam *params;
        int nparams = jailparam_all(&params);
        printf("number of params: %d\n", nparams);
        for (int i=0; i<nparams; i++) {   
                printf("jailparam: %s\n", jailparam_export(&params[i]));
        jailparam_free(params, nparams);
        return 0;
=== listjailparams.c ===

=== listjailparams.py ===

from ctypes import Structure, c_char_p, CDLL, POINTER, c_int, byref

class JailParam(Structure):
        _fields_ = [ 
                ("name", c_char_p),
                ("value", c_char_p),
JailParam_PTR = POINTER(JailParam)

lib = CDLL("libjail.so")

jailparam_all = lib.jailparam_all
jailparam_all.argtypes = [POINTER(JailParam_PTR)]
jailparam_all.restype = c_int

jailparam_free = lib.jailparam_free
jailparam_free.argtypes = [JailParam_PTR, c_int]

params = JailParam_PTR()
nparams = jailparam_all(byref(params))
print(f'nparams: {nparams}')
for i in range(nparams):
        param = params[i]
        name = param.name.decode('utf-8')
        value = param.value if param.value is None else
        print(f'Name: {name}, Value: {value}')
jailparam_free(params, nparams)
=== listjailparams.py ===

You are receiving this mail because:
You are the assignee for the bug.