pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Pkg segfaults when adding a package whose manifest does not have abi or arch

Open galdor opened this issue 3 years ago • 0 comments

If the +MANIFEST file does not contain abi or arch, pkg add segfaults.

For example:

{
  "name": "example",
  "version": "1.0.0",
  "comment": "example package",
  "desc": "Example package.",
  "origin": "misc/example",
  "www": "https://github.com/example/example",
  "maintainer": "Nicolas Martyanoff <[email protected]>",
  "prefix": "/"
}

With GDB:

(gdb) bt
#0  0x0000000800cf46c0 in strncasecmp_l () from /lib/libc.so.7
#1  0x000000000048b490 in is_valid_abi ()
#2  0x00000000004707ad in pkg_add_common ()
#3  0x00000000004705a8 in pkg_add ()
#4  0x00000000002a9c2d in exec_add ()
#5  0x00000000002b32e6 in main ()

The problem is that pkg_add_check_pkg_archive assumes that either pkg->abi or pkg->arch is not null.

There are two possibilities:

  1. Make arch mandatory and make sure it is not null in pkg_is_valid.
  2. Do not call is_valid_abi if both abi and arch are null.

Do you have a preference ? I do not see the point in forcing arch (some packages are arch-independent), but it is up to you. I can send a patch.

Context: I'm writing a program to generate freebsd packages which automatically builds the file/directory index, generates the pre-install script for the required users, etc.

galdor avatar Sep 09 '22 10:09 galdor