Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: embedded null byte #27

Open
Flowdalic opened this issue Oct 23, 2021 · 2 comments · May be fixed by #44
Open

ValueError: embedded null byte #27

Flowdalic opened this issue Oct 23, 2021 · 2 comments · May be fixed by #44

Comments

@Flowdalic
Copy link
Contributor

Flowdalic commented Oct 23, 2021

I get ValueError: embedded null byte when running eclean-kernel version 2.99.3:

* Removing kernel 5.13.16-gentoo-dist (not referenced by bootloader (grub2))                                                                                                             
Traceback (most recent call last):                                                                        
  File "/usr/lib/python-exec/python3.9/eclean-kernel", line 33, in <module>                                                                                                              
    sys.exit(load_entry_point('eclean-kernel==2.99.3', 'console_scripts', 'eclean-kernel')())   
  File "/usr/lib/python3.9/site-packages/ecleankernel/__main__.py", line 382, in setuptools_main                                                                                         
    sys.exit(main(sys.argv[1:]))                                                                                                                                                         
  File "/usr/lib/python3.9/site-packages/ecleankernel/__main__.py", line 332, in main                                                                                                    
    p = subprocess.Popen(scmd)                                                                            
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__                                 self._execute_child(args, executable, preexec_fn, close_fds,                                                                                                                         
  File "/usr/lib/python3.9/subprocess.py", line 1754, in _execute_child                                                                                                                  
    self.pid = _posixsubprocess.fork_exec(     
ValueError: embedded null byte

Using pdb shows the null byte:

* Removing kernel 5.13.15-gentoo-dist (not referenced by bootloader (grub2))
> /usr/lib/python3.9/site-packages/ecleankernel/__main__.py(332)main()
-> p = subprocess.Popen(scmd)
(Pdb) 
 [-] /boot/vmlinuz-5.13.15-gentoo-dist
 [-] /lib/modules/5.13.15-gentoo-dist
 [-] /boot/System.map-5.13.15-gentoo-dist
 [-] /boot/config-5.13.15-gentoo-dist
* Removing kernel 5.13.15-gentoo-dist (not referenced by bootloader (grub2))
> /usr/lib/python3.9/site-packages/ecleankernel/__main__.py(332)main()-> p = subprocess.Popen(scmd)
(Pdb) p scmd
['kernel-install', 'remove', '\x00CIFS', '/boot/initramfs-5.13.15-gentoo-dist.img']
(Pdb) p kf.internal_version
'\x00CIFS'
(Pdb) p kf
KernelImage(PosixPath('/boot/initramfs-5.13.15-gentoo-dist.img'))

Maybe a bug in KernelImage.read_internal_version()?

@mgorny
Copy link
Member

mgorny commented Mar 17, 2022

Looks like it. Could you try debugging it?

@Flowdalic
Copy link
Contributor Author

Flowdalic commented Oct 12, 2023

Here is what I have so far:

This appears to only happen if eclean-kernel looks at an initramfs. Here read_version_from_raw() returns the wrong information:

> /usr/lib/python3.11/site-packages/ecleankernel/file.py(216)read_version_from_raw()
-> return sbuf
(Pdb) p sbuf
b'\x00CIFS VFS Client for Linux\x00fs/smb/client/sess.c\x00OS/2\x00CIFS: %s: OS/2 server\n\x00CIFS: %s: bleft %d\n\x00CIFS: %s: serverOS=%s\n\x00CIFS: %s: serverNOS=%s\n\x00CIFS: %s: serverDomain=%s\n\x00CIFS: %s: Guest login\n\x00CIFS: %s: UID = %llu\n\x00fs/smb/client/cifsglob.h\x00yes\x00no\x00\x00%s: ses '
(Pdb) bt
  /usr/lib/python3.11/bdb.py(600)run()
-> exec(cmd, globals, locals)
  <string>(1)<module>()
  /usr/lib/python-exec/python-exec2(98)<module>()
-> exec(data, new_globals)
  <string>(8)<module>()
  /usr/lib/python3.11/site-packages/ecleankernel/__main__.py(392)setuptools_main()
-> sys.exit(main(sys.argv[1:]))
  /usr/lib/python3.11/site-packages/ecleankernel/__main__.py(237)main()
-> kernels = layout.find_kernels(exclusions=exclusions)
  /usr/lib/python3.11/site-packages/ecleankernel/layout/std.py(94)find_kernels()
-> kobj = KernelImage(path)
  /usr/lib/python3.11/site-packages/ecleankernel/file.py(112)__init__()
-> self.internal_version = self.read_internal_version()
  /usr/lib/python3.11/site-packages/ecleankernel/file.py(163)read_internal_version()
-> verbuf = func(f)
> /usr/lib/python3.11/site-packages/ecleankernel/file.py(216)read_version_from_raw()
-> return sbuf

Looking at read_version_from_raw() in file.py the whole approach appears to be fragile and prone to false positives. Which is nicely demonstrated by this issue.

Flowdalic added a commit to Flowdalic/eclean-kernel that referenced this issue Oct 12, 2023
Ignore the "parsed" Linux kernel version information if there are
non-ASCII at the beginning of the selected buffer.

Fixes projg2#27.

Signed-off-by: Florian Schmaus <[email protected]>
@Flowdalic Flowdalic linked a pull request Oct 12, 2023 that will close this issue
Flowdalic added a commit to Flowdalic/eclean-kernel that referenced this issue Oct 12, 2023
Ignore the "parsed" Linux kernel version information if there are
non-ASCII at the beginning of the selected buffer.

Fixes projg2#27.

Signed-off-by: Florian Schmaus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants