compat/inet_ntop: fix off-by-one in inet_ntop4

Our compat inet_ntop4 function writes to a temporary buffer
with snprintf, and then uses strcpy to put the result into
the final "dst" buffer. We check the return value of
snprintf against the size of "dst", but fail to account for
the NUL terminator. As a result, we may overflow "dst" with
a single NUL. In practice, this doesn't happen because the
output of inet_ntop is limited, and we provide buffers that
are way oversized.

We can fix the off-by-one check easily, but while we are
here let's also use strlcpy for increased safety, just in
case there are other bugs lurking.

As a side note, this compat code seems to be BSD-derived.
Searching for "vixie inet_ntop" turns up NetBSD's latest
version of the same code, which has an identical fix (and
switches to strlcpy, too!).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 4327ae7e50a7f13fb1354203f6395d65d83aebfa
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. ewah/
  7. git-gui/
  8. gitk-git/
  9. gitweb/
  10. mergetools/
  11. perl/
  12. po/
  13. ppc/
  14. t/
  15. templates/
  16. vcs-svn/
  17. xdiff/
  18. .gitattributes
  19. .gitignore
  20. .mailmap
  21. abspath.c
  22. aclocal.m4
  23. advice.c
  24. advice.h
  25. alias.c
  26. alloc.c
  27. archive-tar.c
  28. archive-zip.c
  29. archive.c
  30. archive.h
  31. argv-array.c
  32. argv-array.h
  33. attr.c
  34. attr.h
  35. base85.c
  36. bisect.c
  37. bisect.h
  38. blob.c
  39. blob.h
  40. branch.c
  41. branch.h
  42. builtin.h
  43. bulk-checkin.c
  44. bulk-checkin.h
  45. bundle.c
  46. bundle.h
  47. cache-tree.c
  48. cache-tree.h
  49. cache.h
  50. check-builtins.sh
  51. check-racy.c
  52. check_bindir
  53. color.c
  54. color.h
  55. column.c
  56. column.h
  57. combine-diff.c
  58. command-list.txt
  59. commit-slab.h
  60. commit.c
  61. commit.h
  62. config.c
  63. config.mak.in
  64. config.mak.uname
  65. configure.ac
  66. connect.c
  67. connect.h
  68. connected.c
  69. connected.h
  70. convert.c
  71. convert.h
  72. copy.c
  73. COPYING
  74. credential-cache--daemon.c
  75. credential-cache.c
  76. credential-store.c
  77. credential.c
  78. credential.h
  79. csum-file.c
  80. csum-file.h
  81. ctype.c
  82. daemon.c
  83. date.c
  84. decorate.c
  85. decorate.h
  86. delta.h
  87. diff-delta.c
  88. diff-lib.c
  89. diff-no-index.c
  90. diff.c
  91. diff.h
  92. diffcore-break.c
  93. diffcore-delta.c
  94. diffcore-order.c
  95. diffcore-pickaxe.c
  96. diffcore-rename.c
  97. diffcore.h
  98. dir.c
  99. dir.h
  100. editor.c
  101. entry.c
  102. environment.c
  103. exec_cmd.c
  104. exec_cmd.h
  105. fast-import.c
  106. fetch-pack.c
  107. fetch-pack.h
  108. fmt-merge-msg.h
  109. fsck.c
  110. fsck.h
  111. generate-cmdlist.sh
  112. gettext.c
  113. gettext.h
  114. git-add--interactive.perl
  115. git-archimport.perl
  116. git-bisect.sh
  117. git-compat-util.h
  118. git-cvsexportcommit.perl
  119. git-cvsimport.perl
  120. git-cvsserver.perl
  121. git-difftool--helper.sh
  122. git-difftool.perl
  123. git-filter-branch.sh
  124. git-instaweb.sh
  125. git-merge-octopus.sh
  126. git-merge-one-file.sh
  127. git-merge-resolve.sh
  128. git-mergetool--lib.sh
  129. git-mergetool.sh
  130. git-p4.py
  131. git-parse-remote.sh
  132. git-quiltimport.sh
  133. git-rebase--am.sh
  134. git-rebase--interactive.sh
  135. git-rebase--merge.sh
  136. git-rebase.sh
  137. git-relink.perl
  138. git-remote-testgit.sh
  139. git-request-pull.sh
  140. git-send-email.perl
  141. git-sh-i18n.sh
  142. git-sh-setup.sh
  143. git-stash.sh
  144. git-submodule.sh
  145. git-svn.perl
  146. GIT-VERSION-GEN
  147. git-web--browse.sh
  148. git.c
  149. git.rc
  150. git.spec.in
  151. gpg-interface.c
  152. gpg-interface.h
  153. graph.c
  154. graph.h
  155. grep.c
  156. grep.h
  157. hashmap.c
  158. hashmap.h
  159. help.c
  160. help.h
  161. hex.c
  162. http-backend.c
  163. http-fetch.c
  164. http-push.c
  165. http-walker.c
  166. http.c
  167. http.h
  168. ident.c
  169. imap-send.c
  170. INSTALL
  171. khash.h
  172. kwset.c
  173. kwset.h
  174. levenshtein.c
  175. levenshtein.h
  176. LGPL-2.1
  177. line-log.c
  178. line-log.h
  179. line-range.c
  180. line-range.h
  181. list-objects.c
  182. list-objects.h
  183. ll-merge.c
  184. ll-merge.h
  185. lockfile.c
  186. lockfile.h
  187. log-tree.c
  188. log-tree.h
  189. mailmap.c
  190. mailmap.h
  191. Makefile
  192. match-trees.c
  193. merge-blobs.c
  194. merge-blobs.h
  195. merge-recursive.c
  196. merge-recursive.h
  197. merge.c
  198. mergesort.c
  199. mergesort.h
  200. name-hash.c
  201. notes-cache.c
  202. notes-cache.h
  203. notes-merge.c
  204. notes-merge.h
  205. notes-utils.c
  206. notes-utils.h
  207. notes.c
  208. notes.h
  209. object.c
  210. object.h
  211. pack-bitmap-write.c
  212. pack-bitmap.c
  213. pack-bitmap.h
  214. pack-check.c
  215. pack-objects.c
  216. pack-objects.h
  217. pack-revindex.c
  218. pack-revindex.h
  219. pack-write.c
  220. pack.h
  221. pager.c
  222. parse-options-cb.c
  223. parse-options.c
  224. parse-options.h
  225. patch-delta.c
  226. patch-ids.c
  227. patch-ids.h
  228. path.c
  229. pathspec.c
  230. pathspec.h
  231. pkt-line.c
  232. pkt-line.h
  233. preload-index.c
  234. pretty.c
  235. prio-queue.c
  236. prio-queue.h
  237. progress.c
  238. progress.h
  239. prompt.c
  240. prompt.h
  241. quote.c
  242. quote.h
  243. reachable.c
  244. reachable.h
  245. read-cache.c
  246. README
  247. ref-filter.c
  248. ref-filter.h
  249. reflog-walk.c
  250. reflog-walk.h
  251. refs.c
  252. refs.h
  253. remote-curl.c
  254. remote-testsvn.c
  255. remote.c
  256. remote.h
  257. replace_object.c
  258. rerere.c
  259. rerere.h
  260. resolve-undo.c
  261. resolve-undo.h
  262. revision.c
  263. revision.h
  264. run-command.c
  265. run-command.h
  266. send-pack.c
  267. send-pack.h
  268. sequencer.c
  269. sequencer.h
  270. server-info.c
  271. setup.c
  272. sh-i18n--envsubst.c
  273. sha1-array.c
  274. sha1-array.h
  275. sha1-lookup.c
  276. sha1-lookup.h
  277. sha1_file.c
  278. sha1_name.c
  279. shallow.c
  280. shell.c
  281. shortlog.h
  282. show-index.c
  283. sideband.c
  284. sideband.h
  285. sigchain.c
  286. sigchain.h
  287. split-index.c
  288. split-index.h
  289. strbuf.c
  290. strbuf.h
  291. streaming.c
  292. streaming.h
  293. string-list.c
  294. string-list.h
  295. submodule-config.c
  296. submodule-config.h
  297. submodule.c
  298. submodule.h
  299. symlinks.c
  300. tag.c
  301. tag.h
  302. tar.h
  303. tempfile.c
  304. tempfile.h
  305. test-chmtime.c
  306. test-config.c
  307. test-ctype.c
  308. test-date.c
  309. test-delta.c
  310. test-dump-cache-tree.c
  311. test-dump-split-index.c
  312. test-dump-untracked-cache.c
  313. test-genrandom.c
  314. test-hashmap.c
  315. test-index-version.c
  316. test-line-buffer.c
  317. test-match-trees.c
  318. test-mergesort.c
  319. test-mktemp.c
  320. test-parse-options.c
  321. test-path-utils.c
  322. test-prio-queue.c
  323. test-read-cache.c
  324. test-regex.c
  325. test-revision-walking.c
  326. test-run-command.c
  327. test-scrap-cache-tree.c
  328. test-sha1-array.c
  329. test-sha1.c
  330. test-sha1.sh
  331. test-sigchain.c
  332. test-string-list.c
  333. test-submodule-config.c
  334. test-subprocess.c
  335. test-svn-fe.c
  336. test-urlmatch-normalization.c
  337. test-wildmatch.c
  338. thread-utils.c
  339. thread-utils.h
  340. trace.c
  341. trace.h
  342. trailer.c
  343. trailer.h
  344. transport-helper.c
  345. transport.c
  346. transport.h
  347. tree-diff.c
  348. tree-walk.c
  349. tree-walk.h
  350. tree.c
  351. tree.h
  352. unicode_width.h
  353. unimplemented.sh
  354. unix-socket.c
  355. unix-socket.h
  356. unpack-trees.c
  357. unpack-trees.h
  358. update_unicode.sh
  359. upload-pack.c
  360. url.c
  361. url.h
  362. urlmatch.c
  363. urlmatch.h
  364. usage.c
  365. userdiff.c
  366. userdiff.h
  367. utf8.c
  368. utf8.h
  369. varint.c
  370. varint.h
  371. version.c
  372. version.h
  373. versioncmp.c
  374. walker.c
  375. walker.h
  376. wildmatch.c
  377. wildmatch.h
  378. wrap-for-bin.sh
  379. wrapper.c
  380. write_or_die.c
  381. ws.c
  382. wt-status.c
  383. wt-status.h
  384. xdiff-interface.c
  385. xdiff-interface.h
  386. zlib.c