forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb00a088
committed
Replace a bunch more uses of strncpy() with safer coding.
strncpy() has a well-deserved reputation for being unsafe, so make aneffort to get rid of nearly all occurrences in HEAD.A large fraction of the remaining uses were passing length less than orequal to the known strlen() of the source, in which case no null-paddingcan occur and the behavior is equivalent to memcpy(), though doubtlessslower and certainly harder to reason about. So just use memcpy() inthese cases.In other cases, use either StrNCpy() or strlcpy() as appropriate (dependingon whether padding to the full length of the destination buffer seemsuseful).I left a few strncpy() calls alone in the src/timezone/ code, to keep itin sync with upstream (the IANA tzcode distribution). There are also afew such calls in ecpg that could possibly do with more analysis.AFAICT, none of these changes are more than cosmetic, except for the fouroccurrences in fe-secure-openssl.c, which are in fact buggy: an overlengthsource leads to a non-null-terminated destination buffer and ensuingmisbehavior. These don't seem like security issues, first because no stackclobber is possible and second because if your values of sslcert etc arecoming from untrusted sources then you've got problems way worse than this.Still, it's undesirable to have unpredictable behavior for overlengthinputs, so back-patch those four changes to all active branches.1 parent5d784c7 commitb00a088
1 file changed
+4
-4
lines changedLines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1073 | 1073 |
| |
1074 | 1074 |
| |
1075 | 1075 |
| |
1076 |
| - | |
| 1076 | + | |
1077 | 1077 |
| |
1078 | 1078 |
| |
1079 | 1079 |
| |
| |||
1264 | 1264 |
| |
1265 | 1265 |
| |
1266 | 1266 |
| |
1267 |
| - | |
| 1267 | + | |
1268 | 1268 |
| |
1269 | 1269 |
| |
1270 | 1270 |
| |
| |||
1327 | 1327 |
| |
1328 | 1328 |
| |
1329 | 1329 |
| |
1330 |
| - | |
| 1330 | + | |
1331 | 1331 |
| |
1332 | 1332 |
| |
1333 | 1333 |
| |
| |||
1365 | 1365 |
| |
1366 | 1366 |
| |
1367 | 1367 |
| |
1368 |
| - | |
| 1368 | + | |
1369 | 1369 |
| |
1370 | 1370 |
| |
1371 | 1371 |
| |
|
0 commit comments
Comments
(0)