Merge pull request #147778 from trofi/fix-gptfdisk-on-ncurses-6.3

authored by Sandro and committed by GitHub db0968ba c876d31b

+102
+6
pkgs/tools/system/gptfdisk/default.nix
··· 11 11 sha256 = "sha256-ldGYVvAE2rxLjDQrJhLo0KnuvdUgBClxiDafFS6dxt8="; 12 12 }; 13 13 14 + patches = [ 15 + # fix build failure against ncurses-6.3 (pending upstream inclusion): 16 + # https://sourceforge.net/p/gptfdisk/mailman/message/37392412/ 17 + ./ncurses-6.3.patch 18 + ]; 19 + 14 20 postPatch = '' 15 21 patchShebangs gdisk_test.sh 16 22 '' + lib.optionalString stdenv.isDarwin ''
+96
pkgs/tools/system/gptfdisk/ncurses-6.3.patch
··· 1 + From 9d5032d1487a8fe6ef7229d413418a27e32a28e5 Mon Sep 17 00:00:00 2001 2 + From: Sergei Trofimovich <slyich@gmail.com> 3 + Date: Mon, 1 Nov 2021 07:51:10 +0000 4 + Subject: [PATCH:gptfdisk] gptcurses.cc: always use "%s"-style format for printf()-style 5 + functions 6 + 7 + `ncuses-6.3` added printf-style function attributes and now makes 8 + it easier to catch cases when user input is used in palce of format 9 + string when built with CFLAGS=-Werror=format-security: 10 + 11 + gptcurses.cc:274:10: error: 12 + format not a string literal and no format arguments [-Werror=format-security] 13 + 274 | printw(theLine.c_str()); 14 + | ~~~~~~^~~~~~~~~~~~~~~~~ 15 + 16 + Let's wrap all the missing places with "%s" format. 17 + --- 18 + gptcurses.cc | 24 ++++++++++++------------ 19 + 1 file changed, 12 insertions(+), 12 deletions(-) 20 + 21 + --- a/gptcurses.cc 22 + +++ b/gptcurses.cc 23 + @@ -239,22 +239,22 @@ Space* GPTDataCurses::ShowSpace(int spaceNum, int lineNum) { 24 + ClearLine(lineNum); 25 + if (space->partNum == -1) { // space is empty 26 + move(lineNum, 12); 27 + - printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); 28 + + printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); 29 + move(lineNum, 24); 30 + printw("free space"); 31 + } else { // space holds a partition 32 + move(lineNum, 3); 33 + printw("%d", space->partNum + 1); 34 + move(lineNum, 12); 35 + - printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); 36 + + printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); 37 + move(lineNum, 24); 38 + - printw(space->origPart->GetTypeName().c_str()); 39 + + printw("%s", space->origPart->GetTypeName().c_str()); 40 + move(lineNum, 50); 41 + #ifdef USE_UTF16 42 + space->origPart->GetDescription().extract(0, 39, temp, 39); 43 + - printw(temp); 44 + + printw("%s", temp); 45 + #else 46 + - printw(space->origPart->GetDescription().c_str()); 47 + + printw("%s", space->origPart->GetDescription().c_str()); 48 + #endif 49 + } // if/else 50 + } // if 51 + @@ -271,10 +271,10 @@ int GPTDataCurses::DisplayParts(int selected) { 52 + 53 + move(lineNum++, 0); 54 + theLine = "Part. # Size Partition Type Partition Name"; 55 + - printw(theLine.c_str()); 56 + + printw("%s", theLine.c_str()); 57 + move(lineNum++, 0); 58 + theLine = "----------------------------------------------------------------"; 59 + - printw(theLine.c_str()); 60 + + printw("%s", theLine.c_str()); 61 + numToShow = LINES - RESERVED_TOP - RESERVED_BOTTOM; 62 + pageNum = selected / numToShow; 63 + for (i = pageNum * numToShow; i <= (pageNum + 1) * numToShow - 1; i++) { 64 + @@ -636,7 +636,7 @@ void GPTDataCurses::DisplayOptions(char selectedKey) { 65 + } // if/else 66 + } // for 67 + move(LINES - 1, (COLS - optionDesc.length()) / 2); 68 + - printw(optionDesc.c_str()); 69 + + printw("%s", optionDesc.c_str()); 70 + currentKey = selectedKey; 71 + } // if 72 + } // GPTDataCurses::DisplayOptions() 73 + @@ -748,11 +748,11 @@ void GPTDataCurses::DrawMenu(void) { 74 + 75 + clear(); 76 + move(0, (COLS - title.length()) / 2); 77 + - printw(title.c_str()); 78 + + printw("%s", title.c_str()); 79 + move(2, (COLS - drive.length()) / 2); 80 + - printw(drive.c_str()); 81 + + printw("%s", drive.c_str()); 82 + move(3, (COLS - size.str().length()) / 2); 83 + - printw(size.str().c_str()); 84 + + printw("%s", size.str().c_str()); 85 + DisplayParts(currentSpaceNum); 86 + } // DrawMenu 87 + 88 + @@ -802,7 +802,7 @@ void PromptToContinue(void) { 89 + void Report(string theText) { 90 + clear(); 91 + move(0, 0); 92 + - printw(theText.c_str()); 93 + + printw("%s", theText.c_str()); 94 + move(LINES - 2, (COLS - 29) / 2); 95 + printw("Press any key to continue...."); 96 + cbreak();