Skip to content

EX 23-4: outputError has a possibility of a buffer overflow #7

@dfhawthorne

Description

@dfhawthorne

make test_4 returns the following warnings:

gcc -o ptmr_sigev_thread ptmr_sigev_thread.c error_functions.c get_num.c itimerspec_from_str.c curr_time.c
error_functions.c: In function ‘outputError’:
error_functions.c:54:35: warning: ‘%s’ directive output may be truncated writing up to 499 bytes into a region of size 495 [-Wformat-truncation=]
   54 |     snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);
      |                                   ^~        ~~~~~~~
error_functions.c:54:5: note: ‘snprintf’ output between 8 and 1006 bytes into a destination of size 500
   54 |     snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem right

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions