[asterisk-bugs] [Zaptel 0011471]: [patch] unsafe use of strncpy
noreply at bugs.digium.com
noreply at bugs.digium.com
Tue Jan 22 07:05:45 CST 2008
A NOTE has been added to this issue.
======================================================================
http://bugs.digium.com/view.php?id=11471
======================================================================
Reported By: flefoll
Assigned To: tzafrir
======================================================================
Project: Zaptel
Issue ID: 11471
Category: General
Reproducibility: always
Severity: minor
Priority: normal
Status: assigned
Zaptel Version: SVN
SVN Branch (only for SVN checkouts, not tarball releases): 1.4
SVN Revision (number only!): 3317
Disclaimer on File?: N/A
Request Review:
======================================================================
Date Submitted: 12-05-2007 03:15 CST
Last Modified: 01-22-2008 07:05 CST
======================================================================
Summary: [patch] unsafe use of strncpy
Description:
strncpy(dst, src, len) makes a copy of src towards dst, limited to len
characters, but does NOT guarantee a final null character. So if you want
to obtain a "traditional" null-terminated string, extra work is required.
Zaptel uses strncpy in many places, but most often does not do this extra
work, while destination initial contents is undetermined (stack, ...).
I suggest to use snprintf() instead of strncpy(), since snprintf does
guarantee a final null character. Constraint : snprintf requires including
stdio.h, while strncpy requires including strings.h.
See additional information for the list of files that use strncpy.
I will upload patches for a number of them (not all at the moment).
The same work should be done on SVN Trunk, but it did not compile
yesterday for me (Fedora 7)
======================================================================
----------------------------------------------------------------------
flefoll - 01-22-08 07:05
----------------------------------------------------------------------
Because many files are involved in this issue, what about ...
- first, defining zap_copy_string() function in zaptel.h,
- next, fixing incorrect strncpy() calls progressively, file by file ?
I have uploaded "zaptel.h.br14.3708.patch-zap_copy_string" for zaptel.h
rev 3708 in SVN zaptel/branches/1.4. zap_copy_string() is a
quasi-copy/paste (doxygen comments included) of Asterisk ast_copy_string().
Issue History
Date Modified Username Field Change
======================================================================
01-22-08 07:05 flefoll Note Added: 0080992
======================================================================
More information about the asterisk-bugs
mailing list