Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Aug 2023 18:34:00 +0000
From:      "John F Carr" <jfc@mit.edu>
To:        Current FreeBSD <freebsd-current@freebsd.org>
Subject:   sscanf change prevents build of CURRENT
Message-ID:  <E4534862-C17A-4D69-AEB1-FBCAC93E40A5@mit.edu>

next in thread | raw e-mail | index | archive | help
I had a problem yesterday and today rebuilding a -CURRENT system from sourc=
e:

  --- magic.mgc ---
  ./mkmagic magic
  magic, 4979: Warning: Current entry does not yet have a description for a=
dding a MIME type
  mkmagic: could not find any valid magic files!

The cause was an sscanf call unexpectedly failing to parse the input.  This=
 caused
the mkmagic program (internal tool used to build magic number table for fil=
e) to fail.

If I link mkmagic against the static libc.a in /usr/obj then it works.  So =
my installed
libc.so is broken and the latest source works.  I think.  My installed kern=
el is at
76edfabbecde, the end of the binary integer parsing commit series, so my li=
bc
should be the same.

The program below demonstrates the bug.  See src/contrib/file/src for conte=
xt.

I am trying to manually compile a working mkmagic and restart the build to =
get unstuck.

#include <stdio.h>
#include <stdint.h>

struct guid {
	uint32_t data1;
	uint16_t data2;
	uint16_t data3;
	uint8_t data4[8];
};

int main(int argc, char *argv[])
{
  struct guid g =3D {0, 0, 0, {0}};
  char *text =3D "75B22630-668E-11CF-A6D9-00AA0062CE6C";

  if (argc > 1)
    text =3D argv[1];
  int count =3D
    sscanf(text,
           "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
           &g.data1, &g.data2, &g.data3, &g.data4[0], &g.data4[1],
           &g.data4[2], &g.data4[3], &g.data4[4], &g.data4[5],
           &g.data4[6], &g.data4[7]);

  fprintf(stdout,
          "[%d]:\n%08x-%04hx-%04hx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02=
hhx%02hhx\n",
          count,
          g.data1, g.data2, g.data3, g.data4[0], g.data4[1],
          g.data4[2], g.data4[3], g.data4[4], g.data4[5],
          g.data4[6], g.data4[7]);
  return count !=3D 11;
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E4534862-C17A-4D69-AEB1-FBCAC93E40A5>