Module Name: src Committed By: rillig Date: Thu Nov 2 06:09:07 UTC 2023
Modified Files: src/usr.bin/make: var.c Log Message: make: when comparing substrings, don't read beyond the substring's end Right now, Substring_Words terminates each word with a '\0', but that's an implementation detail that is not required by the interface, so don't rely on it. To generate a diff of this commit: cvs rdiff -u -r1.1067 -r1.1068 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1067 src/usr.bin/make/var.c:1.1068 --- src/usr.bin/make/var.c:1.1067 Thu Nov 2 05:55:22 2023 +++ src/usr.bin/make/var.c Thu Nov 2 06:09:07 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1067 2023/11/02 05:55:22 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1068 2023/11/02 06:09:07 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1067 2023/11/02 05:55:22 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1068 2023/11/02 06:09:07 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -3382,10 +3382,19 @@ SubNumDesc(const void *sa, const void *s } static int +Substring_Cmp(Substring a, Substring b) +{ + for (; a.start < a.end && b.start < b.end; a.start++, b.start++) + if (a.start[0] != b.start[0]) + return (unsigned char)a.start[0] + - (unsigned char)b.start[0]; + return (int)((a.end - a.start) - (b.end - b.start)); +} + +static int SubStrAsc(const void *sa, const void *sb) { - return strcmp( - ((const Substring *)sa)->start, ((const Substring *)sb)->start); + return Substring_Cmp(*(const Substring *)sa, *(const Substring *)sb); } static int