[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RIP strncpy(3) and strncat(3)
From: |
Alejandro Colomar |
Subject: |
RIP strncpy(3) and strncat(3) |
Date: |
Mon, 5 Dec 2022 17:19:16 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 |
Hi Branden,
You probably have seen my radical changes regarding string copy functions.
I've seen that groff uses strncpy(3) in a few places, and strncat(3) in one:
$ grep -rn strncpy src/
src/libs/libdriver/input.cpp:1038: strncpy((char *)current_filename, (char
*)fname, len);
src/libs/libdriver/input.cpp:1064: strncpy((char *)current_source_filename,
(char *)fname, len);
src/roff/groff/pipeline.c:134: strncpy(base, p1, p2 - p1);
src/roff/troff/node.cpp:4128: strncpy(new_name, image_filename,
prefix_length);
src/roff/troff/node.cpp:4144: strncpy(name, new_name, (namebuflen - 1));
src/preproc/preconv/preconv.cpp:1160: strncpy(encoding_string, encoding,
MAX_VAR_LEN - 1);
src/preproc/preconv/preconv.cpp:1240: strncpy(fallback_encoding,
locale_charset(), MAX_VAR_LEN - 1);
src/preproc/preconv/preconv.cpp:1276: strncpy(user_encoding, optarg, MAX_VAR_LEN
- 1);
src/preproc/preconv/preconv.cpp:1284: strncpy(fallback_encoding, optarg,
MAX_VAR_LEN - 1);
src/devices/xditview/font.c:326: strncpy (dvi_name, s, m-s);
src/devices/xditview/font.c:333: strncpy (x_name, s, m-s);
src/devices/grolbp/lbp.cpp:255: strncpy(nam, &(f->lbpname[1]),
strlen(f->lbpname) - 2);
src/devices/grohtml/output.cpp:67: strncpy(s, w, n);
$ grep -rn strncat src/
src/roff/troff/input.cpp:7895: strncat(s, fn, fnlen - sizeof(MACRO_POSTFIX)
+ 1);
And that's not counting the uses within gnulib...
You may want to check out the new versions of the manual pages for those two
functions. Hopefully, they'll convince you to wipe them all.
If the pages are not convincing enough, I'm preparing string(7), which will
cover all commonly known string copy functions, and then some, to help
transition to safe functions.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
OpenPGP_signature
Description: OpenPGP digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- RIP strncpy(3) and strncat(3),
Alejandro Colomar <=