Mercurial > vim
comparison runtime/tools/ccfilter.c @ 34074:1629cc65d78d v9.1.0006
patch 9.1.0006: is*() and to*() function may be unsafe
Commit: https://github.com/vim/vim/commit/184f71cc6868a240dc872ed2852542bbc1d43e28
Author: Keith Thompson <Keith.S.Thompson@gmail.com>
Date: Thu Jan 4 21:19:04 2024 +0100
patch 9.1.0006: is*() and to*() function may be unsafe
Problem: is*() and to*() function may be unsafe
Solution: Add SAFE_* macros and start using those instead
(Keith Thompson)
Use SAFE_() macros for is*() and to*() functions
The standard is*() and to*() functions declared in <ctype.h> have
undefined behavior for negative arguments other than EOF. If plain char
is signed, passing an unchecked value from argv for from user input
to one of these functions has undefined behavior.
Solution: Add SAFE_*() macros that cast the argument to unsigned char.
Most implementations behave sanely for negative arguments, and most
character values in practice are non-negative, but it's still best
to avoid undefined behavior.
The change from #13347 has been omitted, as this has already been
separately fixed in commit ac709e2fc0db6d31abb7da96f743c40956b60c3a
(v9.0.2054)
fixes: #13332
closes: #13347
Signed-off-by: Keith Thompson <Keith.S.Thompson@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 04 Jan 2024 21:30:04 +0100 |
parents | 1c75e1974313 |
children |
comparison
equal
deleted
inserted
replaced
34073:7d9c9731e78e | 34074:1629cc65d78d |
---|---|
247 Col = (dec_col ? 1 : 0 ); | 247 Col = (dec_col ? 1 : 0 ); |
248 } | 248 } |
249 | 249 |
250 stay = (echogets(Line2, echo) != NULL); | 250 stay = (echogets(Line2, echo) != NULL); |
251 while ( stay && (Line2[0] == '|') ) | 251 while ( stay && (Line2[0] == '|') ) |
252 { for (p=&Line2[2]; (*p) && (isspace(*p)); p++); | 252 { for (p=&Line2[2]; (*p) && (isspace((unsigned char)*p)); p++); |
253 strcat( Reason, ": " ); | 253 strcat( Reason, ": " ); |
254 strcat( Reason, p ); | 254 strcat( Reason, p ); |
255 Line2[0] = 0; | 255 Line2[0] = 0; |
256 stay = (echogets(Line2, echo) != NULL); | 256 stay = (echogets(Line2, echo) != NULL); |
257 } | 257 } |
263 prefetch = 0; | 263 prefetch = 0; |
264 rv = 0; | 264 rv = 0; |
265 ok = 0; | 265 ok = 0; |
266 if ( !strncmp(Line, "cfe: ", 5) ) | 266 if ( !strncmp(Line, "cfe: ", 5) ) |
267 { p = &Line[5]; | 267 { p = &Line[5]; |
268 Severity = tolower(*p); | 268 Severity = tolower((unsigned char)*p); |
269 p = strchr( &Line[5], ':' ); | 269 p = strchr( &Line[5], ':' ); |
270 if (p == NULL) | 270 if (p == NULL) |
271 { ok = 0; | 271 { ok = 0; |
272 } | 272 } |
273 else | 273 else |
311 if (verbose) | 311 if (verbose) |
312 printf( "[%u]?%s\n", (unsigned)ok, Line ); | 312 printf( "[%u]?%s\n", (unsigned)ok, Line ); |
313 } | 313 } |
314 else | 314 else |
315 { | 315 { |
316 for (p=Reason; (*p) && (isspace(*p)); p++); | 316 for (p=Reason; (*p) && (isspace((unsigned char)*p)); p++); |
317 if ( BasePath[CWDlen] == 0 ) | 317 if ( BasePath[CWDlen] == 0 ) |
318 printf( "%s:%lu:%lu:%c:%s\n", FileName, Row, Col, Severity, p ); | 318 printf( "%s:%lu:%lu:%c:%s\n", FileName, Row, Col, Severity, p ); |
319 else | 319 else |
320 { | 320 { |
321 printf( "%s/%s:%lu:%lu:%c:%s\n", &BasePath[CWDlen+1], FileName, Row, Col, Severity, p ); | 321 printf( "%s/%s:%lu:%lu:%c:%s\n", &BasePath[CWDlen+1], FileName, Row, Col, Severity, p ); |