On Sat, Nov 07, 2026 at 08:30:58AM -0700, Anthony J. Bentley wrote:
> Marc Espie writes:
> > We drop setgid right away.
> >
> > I don't see the point.
> 
> Leave aside that it's setgid. As a matter of course, this program
> parses data written by other users, every time that it runs. It's good
> to have a strict pledge before that happens.

I disagree. 

- pledge won't give you anything.
- the only use of data that's been made is to read
high scores, into a structure with a fixed length char array,
which is very strictly controlled in termes of size.

Yes, there is a problem with that code: the version that
prints the high score table to stdout doesn't sanitize
those strings, and pledge won't help you with that.

I'm looking at the version that displays stuff in windows, That one
has a possible buffer overflow, which is easy to fix.

In both cases, considering we are handling login names, the
main thing to do is to strvis the hell out of things.

Index: Makefile
===================================================================
RCS file: /build/data/openbsd/cvs/ports/games/xkobo/Makefile,v
diff -u -p -r1.41 Makefile
--- Makefile    7 Nov 2026 13:19:30 -0000       1.41
+++ Makefile    10 Nov 2026 10:16:33 -0000
@@ -2,7 +2,7 @@ COMMENT =       multi-way scrolling shoot'em u
 #'
 
 DISTNAME =     xkobo-1.11
-REVISION =     10
+REVISION =     11
 CATEGORIES =   games
 
 SITES =                ${SITE_XCONTRIB:=games/}  \
Index: patches/patch-score_C
===================================================================
RCS file: /build/data/openbsd/cvs/ports/games/xkobo/patches/patch-score_C,v
diff -u -p -r1.1 patch-score_C
--- patches/patch-score_C       7 Nov 2026 13:21:11 -0000       1.1
+++ patches/patch-score_C       10 Nov 2026 10:15:53 -0000
@@ -1,7 +1,7 @@
 Index: score.C
 --- score.C.orig
 +++ score.C
-@@ -29,6 +29,12 @@ extern "C"{
+@@ -29,6 +29,13 @@ extern "C"{
  #include <sys/stat.h>
  #include <sys/types.h>
  #include <pwd.h>
@@ -9,12 +9,13 @@ Index: score.C
 +#include <fcntl.h>
 +#include <string.h>
 +#include <errno.h>
++#include <vis.h>
 +/* OpenBSD: set[ug]id binary MUST say so in this var */
 +mode_t _permit_setugid = S_ISGID;
  }
  #include "xkobo.h"
  #include "score.h"
-@@ -37,6 +43,7 @@ extern "C"{
+@@ -37,6 +44,7 @@ extern "C"{
  int  _scorefile::highscore       = 0;
  char _scorefile::save_path[1024];
  char _scorefile::login_name[64];
@@ -22,7 +23,7 @@ Index: score.C
  
  class uint_little_endian {
      unsigned char byte[4];
-@@ -74,22 +81,29 @@ int s_table_cmp(s_table *a, s_table *b)
+@@ -74,22 +82,29 @@ int s_table_cmp(s_table *a, s_table *b)
      return 0;
  }
  
@@ -61,7 +62,7 @@ Index: score.C
      if ((i=load_block(save_path, &tbl, sizeof(tbl))) < 0){
          fprintf(stderr, "xkobo : (warning) can't read the score-file\n");
      }
-@@ -117,10 +131,13 @@ void _scorefile::record(int new_score, int stage)
+@@ -117,23 +132,32 @@ void _scorefile::record(int new_score, int stage)
          write = 1;
      }
      if (write){
@@ -79,3 +80,55 @@ Index: score.C
      }
      _scorefile::show_high_scores(0);
  }
+ 
++struct visname {
++      char name[64*4+1];
++};
++
+ void _scorefile::show_high_scores(int to_stdout)
+ {
+     s_table tbl[SCORE_SAVE_MAX];
++    visname visname[SCORE_SAVE_MAX];
+     char    path[1024];
+     int i, j;
+     for (i=0; i<SCORE_SAVE_MAX; i++){
+         tbl[i].score = 0;
+         tbl[i].scene = 0;
+         strcpy(tbl[i].name, "foo");
++        strcpy(visname[i].name, "foo");
+     }
+ 
+     struct dirent *direntp;
+@@ -147,6 +171,8 @@ void _scorefile::show_high_scores(int to_stdout)
+         if (stat(path, &st_buffer)) continue;
+         if (!S_ISREG(st_buffer.st_mode)) continue;
+         if (load_block(path, &tbl[i], sizeof(s_table)) < 0) continue;
++      /* avoid buffer overflow */
++      tbl[i].name[63] = 0;
+         if ((++i) >= SCORE_SAVE_MAX) break;
+     }
+     closedir(dp);
+@@ -154,10 +180,13 @@ void _scorefile::show_high_scores(int to_stdout)
+     qsort(tbl, i, sizeof(s_table), 
+           (int (*)(const void *, const void *))s_table_cmp);
+ 
++    for (j=0; j<i; j++)
++      strvis(visname[j].name, tbl[j].name, 0);
++
+     if (to_stdout){
+         printf("Name                     Score    Stages\n");
+         for (j=0; j<i; j++){
+-            printf("%-20s %9u %9u\n", tbl[j].name,
++            printf("%-20s %9u %9u\n", visname[j].name,
+                    (unsigned int)tbl[j].score, (unsigned int)tbl[j].scene);
+         }
+     }
+@@ -169,7 +198,7 @@ void _scorefile::show_high_scores(int to_stdout)
+         wscore.string(180, 24, "high score");
+         wscore.string(80, 24, "cleared stages");
+         for (j=0; j<i; j++){
+-            wscore.string(10, 16*j + 48, tbl[j].name);
++            wscore.string(10, 16*j + 48, visname[j].name);
+             sprintf(buffer, "%09u", (unsigned int)tbl[j].score);
+             wscore.string(180, 16*j + 48, buffer);
+             sprintf(buffer, "%09u", (unsigned int)tbl[j].scene);

Reply via email to