Message ID | 1471485975-1775-1-git-send-email-nhofmeyr@sysmocom.de |
---|---|
State | New |
Headers | show |
> On 18 Aug 2016, at 04:06, Neels Hofmeyr <nhofmeyr@sysmocom.de> wrote: > > For strncat, to obtain n, one must not subtract the length of what is appended, > but the length of what is already written from the buffer size. > let's use talloc_asprintf or the append variant of it. The place doesn't look like performance critical code. holger
diff --git a/gtp/gtp.c b/gtp/gtp.c index 12cb492..34e1dc6 100644 --- a/gtp/gtp.c +++ b/gtp/gtp.c @@ -648,9 +648,10 @@ static void log_restart(struct gsn_t *gsn) int counter = 0; char filename[NAMESIZE]; - filename[NAMESIZE - 1] = 0; /* No null term. guarantee by strncpy */ + /* guarantee nul term, strncpy might omit if too long */ + filename[NAMESIZE - 1] = 0; strncpy(filename, gsn->statedir, NAMESIZE - 1); - strncat(filename, RESTART_FILE, NAMESIZE - 1 - sizeof(RESTART_FILE)); + strncat(filename, RESTART_FILE, NAMESIZE - 1 - strlen(filename)); i = umask(022);