Subject: Re: bug#79194: Segfault with 0 byte symbol

From: Tomas Volf <[email-masked]>
Date: Sun, 10 Aug 2025 16:34:33 +0200

Hi,

a aa <[email-masked]> writes:

> Hello,
>
> how to reproduce:
> cc main.c `pkg-config --libs --cflags guile-3.0` && ./a.out
>
> incorrect behaviour:
> The second parameter for scm_from_utf8_symboln should be how many bytes are
> pointed to by the pointer however the pointer still gets read if the length
> is zero. Being able to handle 0 byte strings is expected since replacing
> the call from scm_from_utf8_symboln to scm_from_utf8_stringn will not have
> a segfault and the documentation for this function does not mention being
> unable to handle 0 byte strings.

Well, the scm_from_utf8_symboln is just not documented at all, so I am
not sure how you have determined that the "documentation for this
function does no mention ...".  But let us ignore that for a moment.

You wrote "handle 0 byte *strings*" (emphasis mine).  That is not what
you are doing.  NULL is not a "0 byte string".  "" (almost) is.  Or a
char* can be.  But not NULL.

>
> [..]
>
> #include <libguile.h>
>
> void* inner_main(void*) {
>   SCM sym = scm_from_utf8_symboln(NULL, 0);

The line should be

    SCM sym = scm_from_utf8_symboln("", 0);

or

    const char zero_str[] = {};
    SCM sym = scm_from_utf8_symboln(zero_str, 0);

Both work fine.  You cannot just send a null pointer to a function that
is supposed to take a string and expect it to work.  So I do not think
it is valid to declare this to be an "incorrect behaviour", maybe
"unexpected" (by you) would be better description.

Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.