mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 08:14:24 +02:00
upstream commit
Fix two rare edge cases: 1. If vasprintf() returns < 0, do not access a NULL pointer in snmprintf(), and do not free() the pointer returned from vasprintf() because on some systems other than OpenBSD, it might be a bogus pointer. 2. If vasprintf() returns == 0, return 0 and "" rather than -1 and NULL. Besides, free(dst) is pointless after failure (not a bug). One half OK martijn@, the other half OK deraadt@; committing quickly before people get hurt. Upstream-ID: b7bcd2e82fc168a8eff94e41f5db336ed986fed0
This commit is contained in:
parent
0e059cdf5f
commit
ac284a355f
22
utf8.c
22
utf8.c
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: utf8.c,v 1.1 2016/05/25 23:48:45 schwarze Exp $ */
|
/* $OpenBSD: utf8.c,v 1.2 2016/05/30 12:05:56 schwarze Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
|
* Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
|
||||||
*
|
*
|
||||||
@ -81,13 +81,15 @@ vasnmprintf(char **str, size_t maxsz, int *wp, const char *fmt, va_list ap)
|
|||||||
int width; /* Display width of the character wc. */
|
int width; /* Display width of the character wc. */
|
||||||
int total_width, max_width, print;
|
int total_width, max_width, print;
|
||||||
|
|
||||||
src = dst = NULL;
|
src = NULL;
|
||||||
if (vasprintf(&src, fmt, ap) <= 0)
|
if ((ret = vasprintf(&src, fmt, ap)) <= 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
sz = strlen(src);
|
sz = strlen(src);
|
||||||
if ((dst = malloc(sz)) == NULL)
|
if ((dst = malloc(sz)) == NULL) {
|
||||||
|
free(src);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (maxsz > INT_MAX)
|
if (maxsz > INT_MAX)
|
||||||
maxsz = INT_MAX;
|
maxsz = INT_MAX;
|
||||||
@ -191,13 +193,16 @@ vasnmprintf(char **str, size_t maxsz, int *wp, const char *fmt, va_list ap)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free(src);
|
|
||||||
free(dst);
|
|
||||||
*str = NULL;
|
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
*wp = 0;
|
*wp = 0;
|
||||||
|
if (ret == 0) {
|
||||||
|
*str = src;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
*str = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
|
snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
|
||||||
@ -209,8 +214,11 @@ snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vasnmprintf(&cp, sz, wp, fmt, ap);
|
ret = vasnmprintf(&cp, sz, wp, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
if (cp != NULL) {
|
||||||
(void)strlcpy(str, cp, sz);
|
(void)strlcpy(str, cp, sz);
|
||||||
free(cp);
|
free(cp);
|
||||||
|
} else
|
||||||
|
*str = '\0';
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user