Skip to content

Commit e069614

Browse files
committed
jsoninfo: make sure that uuid is null-terminated
Since it's used as a string. Coverity: CID 739693 (#1 of 1): String not null terminated (STRING_NULL) At (2): Function "fread(void * restrict, size_t, size_t, FILE * restrict)" does not terminate string "*uuid". At (4): Passing unterminated string "uuid" to "strchr(char const *, int)", which expects a null-terminated string. Signed-off-by: Ferry Huberts <[email protected]>
1 parent 6a42d77 commit e069614

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/jsoninfo/src/olsrd_jsoninfo.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static size_t outbuffer_written[MAX_CLIENTS];
157157
static int outbuffer_socket[MAX_CLIENTS];
158158
static int outbuffer_count;
159159

160-
char uuid[UUIDLEN];
160+
char uuid[UUIDLEN + 1];
161161
char uuidfile[FILENAME_MAX];
162162

163163
static struct timeval start_time;
@@ -423,8 +423,9 @@ read_uuid_from_file(const char *file)
423423
FILE *f;
424424
char* end;
425425
int r = 0;
426+
size_t chars;
426427

427-
*uuid = 0;
428+
memset(uuid, 0, sizeof(uuid));
428429

429430
f = fopen(file, "r");
430431
olsr_printf(1, "(JSONINFO) Reading UUID from '%s'\n", file);
@@ -433,7 +434,10 @@ read_uuid_from_file(const char *file)
433434
file, strerror(errno));
434435
return -1;
435436
}
436-
if (fread(uuid, 1, UUIDLEN, f) > 0) {
437+
chars = fread(uuid, 1, UUIDLEN, f);
438+
if (chars > 0) {
439+
uuid[chars] = '\0'; /* null-terminate the string */
440+
437441
/* we only use the first line of the file */
438442
end = strchr(uuid, '\n');
439443
if(end)

lib/jsoninfo/src/olsrd_jsoninfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
/* #define JSONINFO_ALLOW_LOCALHOST */
5656

5757
#define UUIDLEN 256
58-
extern char uuid[UUIDLEN];
58+
extern char uuid[UUIDLEN + 1];
5959
extern char uuidfile[FILENAME_MAX];
6060

6161
extern union olsr_ip_addr jsoninfo_accept_ip;

0 commit comments

Comments
 (0)