summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-05-23 11:04:04 +0000
committertb <>2023-05-23 11:04:04 +0000
commit816cb4ff9bb4cb6597de02367f7c5abca27b4b58 (patch)
treebda34ebac67612393f45df71186ae432cecdddae /src/lib
parent0a17288b253e10b475dd8136619406dabcabcc66 (diff)
downloadopenbsd-816cb4ff9bb4cb6597de02367f7c5abca27b4b58.tar.gz
openbsd-816cb4ff9bb4cb6597de02367f7c5abca27b4b58.tar.bz2
openbsd-816cb4ff9bb4cb6597de02367f7c5abca27b4b58.zip
Always NUL terminate buf in OBJ_obj2txt()
OBJ_obj2txt() is often called without error checking and is used for reporting unexpected or malformed objects. As such, we should ensure buf is a string even on failure. This had long been the case before it was lost in a recent rewrite. If obj and obj->data are both non-NULL this is already taken care of by i2t_ASN1_OBJECT_internal(), so many callers were still safe. ok miod
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 6adc4068a3..fcc21ddfb4 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.51 2022/12/26 07:18:52 jmc Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.52 2023/05/23 11:04:04 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -499,6 +499,9 @@ OBJ_txt2obj(const char *s, int no_name)
499int 499int
500OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *aobj, int no_name) 500OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *aobj, int no_name)
501{ 501{
502 if (buf_len > 0)
503 buf[0] = '\0';
504
502 if (aobj == NULL || aobj->data == NULL) 505 if (aobj == NULL || aobj->data == NULL)
503 return 0; 506 return 0;
504 507