aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2020-05-26 03:12:29 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2020-05-26 22:30:49 +0200
commit6d67032d5092bdcc8fcd1082a6fb136b4372691e (patch)
treec94d379d4e3961bf90f69c7b127588b9c0400bac
parentdacac990f94cd820724cdfae124a4b5274668263 (diff)
fix osmo_mi_name_c() to always return talloced strings, via osmo_mi_name_buf()
Fix osmo_mi_name_buf() to snprintf() into the buf in *all* cases. osmo_mi_name_c() is implemented via osmo_mi_name_buf(), which returns compile-time string constants in special cases. That means that osmo_mi_name_c() does return non-allocated strings in these special cases. The caller of functions like osmo_mi_name_c() must always be able to rely on getting a talloced string, or run a danger of deallocating const pointers. Change-Id: I623959f01b72642bcdd18508097c5c405c59f6f1
-rw-r--r--src/gsm/gsm48.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 43b10b78..8d0998bb 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -479,9 +479,10 @@ char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_
if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
tmsi = osmo_load32be(&mi[1]);
snprintf(buf, buf_len, "TMSI-0x%08" PRIX32, tmsi);
- return buf;
+ } else {
+ snprintf(buf, buf_len, "TMSI-invalid");
}
- return "TMSI-invalid";
+ return buf;
case GSM_MI_TYPE_IMSI:
case GSM_MI_TYPE_IMEI:
@@ -491,7 +492,8 @@ char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_
return buf;
default:
- return "unknown";
+ snprintf(buf, buf_len, "unknown");
+ return buf;
}
}