Skip to content

Commit

Permalink
alternatives: fix possible overrun
Browse files Browse the repository at this point in the history
Error: STRING_NULL (CWE-170): [#def1] [important]
chkconfig-1.26/alternatives.c:591:13: string_null_source: Function "readlink" does not terminate string "buf". [Note: The source code implementation of the function has been overridden by a builtin model.]
chkconfig-1.26/alternatives.c:593:13: string_null: Passing unterminated string "buf" to "streq", which expects a null-terminated string.
  591|               readlink(l->facility, buf, sizeof(buf));
  592|
  593|->             if(!streq(sl, buf)) {
  594|                   unlink(l->facility);
  595|

Error: STRING_NULL (CWE-170): [#def2] [important]
chkconfig-1.26/alternatives.c:609:9: string_null_source: Function "readlink" does not terminate string "buf". [Note: The source code implementation of the function has been overridden by a builtin model.]
chkconfig-1.26/alternatives.c:611:9: string_null: Passing unterminated string "buf" to "streq", which expects a null-terminated string.
  609|           readlink(sl, buf, sizeof(buf));
  610|
  611|->         if(!streq(l->target, buf)) {
  612|               if (unlink(sl) && errno != ENOENT) {
  613|                   fprintf(stderr, _("failed to remove link %s: %s\n"), sl,
  • Loading branch information
lnykryn committed May 7, 2024
1 parent 3e697b0 commit eb63463
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alternatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ static int makeLinks(struct linkSet *l, const char *altDir, int flags) {
printf(_("would link %s -> %s\n"), l->facility, sl);
} else {
memset(buf, 0, sizeof(buf));
readlink(l->facility, buf, sizeof(buf));
readlink(l->facility, buf, sizeof(buf)-1);

if(!streq(sl, buf)) {
unlink(l->facility);
Expand All @@ -606,7 +606,7 @@ static int makeLinks(struct linkSet *l, const char *altDir, int flags) {
printf(_("would link %s -> %s\n"), sl, l->target);
} else {
memset(buf, 0, sizeof(buf));
readlink(sl, buf, sizeof(buf));
readlink(sl, buf, sizeof(buf)-1);

if(!streq(l->target, buf)) {
if (unlink(sl) && errno != ENOENT) {
Expand Down

0 comments on commit eb63463

Please sign in to comment.