cooklang / cookcli

Command line program which provides a suite of tools to create shopping lists and maintain recipes.
https://cooklang.org
MIT License
780 stars 36 forks source link

`cook shopping-list` segfaults on Ubuntu 21.04 #29

Closed cmdln closed 2 years ago

cmdln commented 2 years ago

Running Pop_OS! 21.04 and invoking cook shopping-list <some cook file> segfaults every time.

dubadub commented 2 years ago

Hi @cmdln thanks for reporting. I wan't able to reproduce it on my Ubuntu (20.04), but I'll try to install a newer one and check again. Would it be possible to share an example recipe file which reproduces that behaviour? Many thanks!

cmdln commented 2 years ago
Add @agave{0.25%cup} to the hot @water{0.5%cup} in a #small bowl{} and allow to dissolve. Stir in the @yeast packet{1} and allow to sit until a layer of foam forms on top.

In a #large mixing bowl{}, combine the yeast starter with the @spent grain{3%cups}, @salt{1%tsp}, and @beer{1%cup}. I like to use my homebrew but any beer that you like will do.

Add the @rye flour{1%cup}, @whole wheat flour{1%cup}, and @aquafaba{0.25%cup}.

Add the @all purpose flour{3%cup} a half cup at a time, mixing thoroughly.

I've attached my aisle.conf, too, which I modified a little from the one cook seed generated. Do I need to make sure ingredients are all in aisle.conf before trying to generate a shopping list?

aisle.zip

dubadub commented 2 years ago

Great, thanks for sharing

huevoncito commented 2 years ago

I have the same problem, also Pop_OS. I have made no changes to aisle.conf and the seg fault occurs with seed recipes (eg. Easy Pancackes.cook).

Thanks for a great tool!

dubadub commented 2 years ago

Sorry, took me a while get back to it. I can confirm that I can reproduce the bug on the latest Pop_OS.

Essentially SIGSEGV happens here https://github.com/cooklang/CookCLI/blob/main/Sources/Catalog/ConfigLoader.swift#L43 while getting user's home directory.

Here's the debugger output:

(gdb) run shopping-list ./Borsch.cook
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f14844 in __GI___nss_readline (poffset=<optimized out>, len=<optimized out>, buf=<optimized out>, fp=<optimized out>) at nss_readline.c:68
68  nss_readline.c: No such file or directory.
(gdb) bt
#0  0x00007ffff7f14844 in __GI___nss_readline (poffset=<optimized out>, len=<optimized out>, 
    buf=<optimized out>, fp=<optimized out>) at nss_readline.c:68
#1  __GI___nss_readline (fp=fp@entry=0x7ffff7c862a0, 
    buf=buf@entry=0x3709810 "root:x:0:0:root:/root:/bin/bash\n", len=len@entry=1024, 
    poffset=poffset@entry=0x7fffffffd660) at nss_readline.c:26
#2  0x00007ffff7f1a4e2 in internal_getent (errnop=<optimized out>, buflen=<optimized out>, 
    buffer=<optimized out>, result=<optimized out>, stream=<optimized out>) at nss_files/files-XXX.c:124
#3  __GI__nss_files_getpwuid_r (uid=<optimized out>, result=0x36f3220 <resbuf>, 
    buffer=0x3709810 "root:x:0:0:root:/root:/bin/bash\n", buflen=1024, errnop=0x36f58f0)
    at nss_files/files-pwd.c:40
#4  0x00000000010245c5 in getpwuid_r ()
#5  0x0000000001023f98 in getpwuid ()
#6  0x0000000000c3a6e0 in CFCopyUserName ()
#7  0x0000000000777cea in $s10Foundation10NSUserNameSSyF ()
#8  0x00000000006b7179 in $s10Foundation11FileManagerC27homeDirectoryForCurrentUserAA3URLVvg ()
#9  0x000000000051ac7a in $s7Catalog12ConfigLoaderC04findB4File33_FBEF48852F8E4F39368408162129A1CDLL4type_SSSgSS_AGtF (type=..., provided=..., self=...) at /src/Sources/Catalog/ConfigLoader.swift:43
#10 0x000000000051a68d in $s7Catalog12ConfigLoaderC4load4type10referenced11CookInSwift0gB0CSgSS_SSSgtKF (
    type=..., referenced=..., self=...) at /src/Sources/Catalog/ConfigLoader.swift:22
#11 0x000000000053addf in $s7CookCLI0A0V12ShoppingListV3runyyKF (self=...)
    at /src/Sources/CookCLI/Commands/ShoppingList.swift:50
#12 0x000000000053eff3 in $s7CookCLI0A0V12ShoppingListV14ArgumentParser15ParsableCommandAafGP3runyyKFTW ()
    at /src/Sources/CookCLI/Commands/ShoppingList.swift:37
#13 0x000000000045c4e1 in $s14ArgumentParser15ParsableCommandPAAE4mainyySaySSGSgFZ (arguments=..., self=...)
    at /src/.build/checkouts/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift:95
#14 0x000000000045c627 in $s14ArgumentParser15ParsableCommandPAAE4mainyyFZ (self=...)
    at /src/.build/checkouts/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift:105
#15 0x000000000054bc2e in main () at /src/Sources/CookCLI/main.swift:9
(gdb) q

Also strace output:

...
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2694, ...}, AT_EMPTY_PATH) = 0
lseek(3, 0, SEEK_SET)                   = 0
read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 2694
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xe5} ---
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)

glibc version:

$ ldd --version ldd
ldd (Ubuntu GLIBC 2.34-0ubuntu3) 2.34

Similar issue reported for statically compiled binaries which use nss library after update to glibc version 2.32+ .

I'll try to update glibc in a Docker image I use for building and check if it can fix it and it still works for older systems too. If not probably need to find another way to get home directory.