Skip to content
Snippets Groups Projects
Commit 229a2007 authored by Alan Carvalho de Assis's avatar Alan Carvalho de Assis Committed by Gregory Nutt
Browse files

Add NULL termination to tune string and fix missing break

parent ead4b601
No related branches found
No related tags found
No related merge requests found
......@@ -495,6 +495,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper)
case 'B':
g_repeat = true;
break;
default:
auderr("unknown symbol: %c!\n", c);
......@@ -863,9 +864,9 @@ static ssize_t tone_read(FAR struct file *filep, FAR char *buffer,
static ssize_t tone_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen)
{
FAR struct inode *inode = filep->f_inode;
FAR struct tone_upperhalf_s *upper = inode->i_private;
int ndx;
/* We need to receive a string #RRGGBB = 7 bytes */
......@@ -876,10 +877,21 @@ static ssize_t tone_write(FAR struct file *filep, FAR const char *buffer,
return -EINVAL;
}
if (buflen >= MAX_TUNE_LEN)
{
/* Too big to it inside internal buffer (with extra NUL terminator) */
return -EINVAL;
}
/* Copy music to internal buffer */
memcpy(tune_buf, buffer, buflen);
/* Failsafe NUL terminated string */
tune_buf[buflen] = '\0';
/* Let the music play */
start_tune(upper, tune_buf);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment