On Wed, 2007-08-22 at 12:33 +0200, Mark Burgess wrote: > Jim Wight wrote: > > The line > > > > strncpy(refbase,refhost,strlen(refhost)); > > > > in FuzzyHostMatch in item.c creates an unterminated string, which, not > > unexpectedly, leads to unpredictable results. > > > > Jim > > > > > > _______________________________________________ > > Bug-cfengine mailing list > > [email protected] > > https://cfengine.org/mailman/listinfo/bug-cfengine > > > > This is impossible Jim. strncpy always terminates strings
I would agree with you if we were talking about strcpy, but for strncpy my man page says: The strncpy() function is similar, except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result will not be null-terminated. If only strlen(refhost) bytes are copied from refhost then they don't include the terminating null. It should strlen(refhost) + 1, or strcpy should be used. A rebuilt 2.2.1 with the patch from the '2.2.1 broken HostRange again?' thread on Mon Jun 25 21:51:47 CEST 2007 which worked yesterday stopped working today. It was when I saw strange characters in the debug output that I suspected what I found. Jim _______________________________________________ Bug-cfengine mailing list [email protected] https://cfengine.org/mailman/listinfo/bug-cfengine
