movienfo | Tools to generate movie/tv nfo for kodi scrapers | Media Player library
kandi X-RAY | movienfo Summary
kandi X-RAY | movienfo Summary
Tools to generate movie/tv nfo for kodi scrapers.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of movienfo
movienfo Key Features
movienfo Examples and Code Snippets
Community Discussions
Trending Discussions on movienfo
QUESTION
You should be able to enter any movie title and genre into this program as long as they are smaller then 30 characters. Then insert a rating between 1-5. The insert
function takes those three inputs and stores them into a doubly linked list. After Two entries into this list the program creates an unexpected breakpoint on this line newBlock = (movieInfo*)malloc(sizeof(movieInfo));
The problems is in the insert
function.
ANSWER
Answered 2021-Feb-22 at 00:51Read carefully what strncpy
does, e.g. at https://en.cppreference.com/w/c/string/byte/strncpy.
If, after copying the terminating null character from src, count is not reached, additional null characters are written to dest until the total of count characters have been written.
So if for instance title
is 12 characters long, then 13 bytes will be allocated for newBlock->title
, but strncpy(newBlock->title, title, 30)
will write a full 30 bytes into that 13-byte array, thus overflowing it.
There is a separate bug if title
is more than 30 characters long. Say it's 50. In this case you have allocated a full 51 bytes, but strncpy
will only copy 30, and moreover:
If count is reached before the entire array src was copied, the resulting character array is not null-terminated.
As such, later attempts to call strcmp
on the created string are likely to crash and/or give incorrect results.
Since you have allocated enough space to hold the entire string, there is no reason to cut it off at 30 characters. It is safe to just do strcpy(newBlock->title, title);
which will fix both bugs and avoid unnecessary truncation to boot. If you really want to limit the title to 30 characters, then check its length when it is first input.
This recent answer has some good advice on using strncpy
, i.e. "don't". Avoiding buffer overflows is important but strncpy
isn't a very good solution.
One more bug is that you've forgotten to fill in newBlock->rating
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install movienfo
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page