소스 검색

dselect: Use m_strdup instead of unchecked malloc + strcpy

This would cause a segfault in an OOM situation.
Guillem Jover 16 년 전
부모
커밋
ecf0b87226
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      dselect/main.cc

+ 2 - 2
dselect/main.cc

@@ -259,11 +259,11 @@ extern "C" {
    *            --color selstate::reverse  // doesn't work FIXME
    */
   static void setcolor(const struct cmdinfo*, const char *string) {
-    char *s= (char *) malloc((strlen(string) + 1) * sizeof(char));
+    char *s;
     char *colours, *attributes, *attrib, *colourname;
     int screenpart, aval;
 
-    strcpy(s, string); // strtok modifies strings, keep string const
+    s = m_strdup(string); // strtok modifies strings, keep string const
     screenpart= findintable(screenparttable, strtok(s, ":"), _("screen part"));
     colours= strtok(NULL, ":");
     attributes= strtok(NULL, ":");