Changeset f68401e in rtems


Ignore:
Timestamp:
Mar 20, 2014, 12:18:44 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c499856
Parents:
6cd4a5c
git-author:
Sebastian Huber <sebastian.huber@…> (03/20/14 12:18:44)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/20/14 12:20:44)
Message:

fstests/fsrename: Fix stack corruption

Use snprintf() instead of sprintf(). Include missing header files.

Location:
testsuites/fstests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/fstests/fsrename/test.c

    r6cd4a5c rf68401e  
    1414#include "fstest.h"
    1515#include "fs_config.h"
     16#include "fstest_support.h"
    1617#include "pmacros.h"
    1718
     
    2627const char rtems_test_name[] = "FSRENAME " FILESYSTEM;
    2728
    28 void test_initialize_filesystem (void);
    29 void test_shutdown_filesystem (void);
    30 
    3129static void symbolic_link_test (void)
    3230{
    3331  int fd;
    3432  int status;
     33  int rv;
    3534
    3635  const char *name01 = "name01";
     
    146145  rtems_test_assert (status == 0);
    147146
    148   sprintf (path01, "%s/test", symlink01);
     147  rv = snprintf (path01, sizeof(path01), "%s/test", symlink01);
     148  rtems_test_assert (rv < sizeof(path01));
    149149  EXPECT_ERROR (ELOOP, rename, path01, name01);
    150150
    151   sprintf (path01, "%s/test", symlink02);
     151  rv = snprintf (path01, sizeof(path01), "%s/test", symlink02);
     152  rtems_test_assert (rv < sizeof(path01));
    152153  EXPECT_ERROR (ELOOP, rename, path01, name01);
    153154
     
    177178  rtems_test_assert (status == 0);
    178179
    179   sprintf (path01, "%s/test", symlink01);
     180  rv = snprintf (path01, sizeof(path01), "%s/test", symlink01);
     181  rtems_test_assert (rv < sizeof(path01));
    180182  EXPECT_ERROR (ELOOP, rename, name01, path01);
    181183
    182   sprintf (path01, "%s/test", symlink02);
     184  rv = snprintf (path01, sizeof(path01), "%s/test", symlink02);
     185  rtems_test_assert (rv < sizeof(path01));
    183186  EXPECT_ERROR (ELOOP, rename, name01, path01);
    184187
     
    210213  int fd;
    211214  int status;
     215  int rv;
    212216
    213217  const char *name01 = "name01";
     
    265269  rtems_test_assert (status == 0);
    266270
    267   sprintf (path01, "%s/%s", dir01, name02);
     271  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name02);
     272  rtems_test_assert (rv < sizeof(path01));
    268273  status = link (name01, path01);
    269274  rtems_test_assert (status == 0);
     
    298303  int fd;
    299304  int status;
     305  int rv;
    300306  int i;
    301307
     
    384390  rtems_test_assert (status == 0);
    385391
    386   sprintf (path01, "%s/%s", dir02, dir01);
     392  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, dir01);
     393  rtems_test_assert (rv < sizeof(path01));
    387394  status = mkdir (path01, mode);
    388395  rtems_test_assert (status == 0);
     
    410417  rtems_test_assert (status == 0);
    411418
    412   sprintf (path01, "%s/%s", dir02, name02);
     419  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name02);
     420  rtems_test_assert (rv < sizeof(path01));
    413421  fd = creat (path01, mode);
    414422  rtems_test_assert (fd >= 0);
     
    471479  for(i = statbuf.st_nlink; i < LINK_MAX_val; i++)
    472480  {
    473     sprintf (link_name, "%s/%d", dir01, i);
     481    rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
     482    rtems_test_assert (rv < sizeof(link_name));
    474483
    475484    status = mkdir (link_name, mode);
     
    480489  rtems_test_assert (status == 0);
    481490
    482   sprintf (path01, "%s/%s", dir01, dir01);
     491  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, dir01);
     492  rtems_test_assert (rv < sizeof(path01));
    483493  EXPECT_ERROR (EMLINK, rename, dir02, path01);
    484494
     
    489499  for(i = statbuf.st_nlink; i < LINK_MAX_val; i++)
    490500  {
    491     sprintf (link_name, "%s/%d", dir01, i);
     501    rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
     502    rtems_test_assert (rv < sizeof(link_name));
    492503
    493504    status = rmdir (link_name);
     
    509520  rtems_test_assert (status == 0);
    510521
    511   sprintf (path01, "%s/%s", dir01, name01);
     522  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
     523  rtems_test_assert (rv < sizeof(path01));
    512524  fd = creat (path01, mode);
    513525  rtems_test_assert (fd >= 0);
     
    551563  rtems_test_assert (status == 0);
    552564
    553   sprintf (path01, "%s/%s", dir01, name01);
     565  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
     566  rtems_test_assert (rv < sizeof(path01));
    554567  fd = creat (path01, mode);
    555568  rtems_test_assert (fd >= 0);
     
    604617  int fd;
    605618  int status;
    606   int i;
     619  int rv;
    607620
    608621  const char *name01 = "name01";
     
    615628  const char *wd = __func__;
    616629
    617   char filename[NAME_MAX + 1];
     630  char filename[NAME_MAX + 2];
    618631  char path01[20];
    619632
     
    678691  rtems_test_assert (status == 0);
    679692
    680   sprintf (path01, "%s/%s/%s", dir01, name01, name02);
     693  rv = snprintf (path01, sizeof(path01), "%s/%s/%s", dir01, name01, name02);
     694  rtems_test_assert (rv < sizeof(path01));
    681695  EXPECT_ERROR (ENOENT, rename, path01, name01);
    682696
     
    720734
    721735  /* Generate string with NAME_MAX + 1 length */
    722 
    723   for(i = 0; i < NAME_MAX + 1; i++)
    724     strcat(filename, "a");
     736  memset(filename, 'a', NAME_MAX + 1);
     737  filename[NAME_MAX + 1] = '\0';
    725738
    726739  EXPECT_ERROR (ENAMETOOLONG, rename, name01, filename);
     
    894907  int fd;
    895908  int status;
     909  int rv;
    896910
    897911  const char *name01 = "name01";
     
    968982  rtems_test_assert (status == 0);
    969983
    970   sprintf (path01, "../%s/%s", dir01, name02);
     984  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
     985  rtems_test_assert (rv < sizeof(path01));
    971986  EXPECT_ERROR (EACCES, rename, name01, path01);
    972987
     
    984999  EXPECT_EQUAL (0, unlink, name01);
    9851000
    986   sprintf (path01, "../%s", dir01);
     1001  rv = snprintf (path01, sizeof(path01), "../%s", dir01);
     1002  rtems_test_assert (rv < sizeof(path01));
    9871003  status = chmod (path01, mode);
    9881004  rtems_test_assert (status == 0);
    9891005
    990   sprintf (path01, "../%s/%s", dir01, name01);
     1006  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name01);
     1007  rtems_test_assert (rv < sizeof(path01));
    9911008  EXPECT_EQUAL (0, unlink, path01);
    9921009
    993   sprintf (path01, "../%s/%s", dir01, name02);
     1010  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
     1011  rtems_test_assert (rv < sizeof(path01));
    9941012  EXPECT_EQUAL (0, unlink, path01);
    9951013
     
    10191037  int fd;
    10201038  int status;
     1039  int rv;
    10211040
    10221041  const char *name01 = "name01";
     
    10551074  rtems_test_assert (status == 0);
    10561075
    1057   sprintf (path01, "%s/%s", dir01, name01);
     1076  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
     1077  rtems_test_assert (rv < sizeof(path01));
    10581078  fd = creat (path01, mode);
    10591079  rtems_test_assert (fd >= 0);
     
    10611081  rtems_test_assert (status == 0);
    10621082
    1063   sprintf (path02, "%s/%s", dir01, name02);
     1083  rv = snprintf (path02, sizeof(path02), "%s/%s", dir01, name02);
     1084  rtems_test_assert (rv < sizeof(path02));
    10641085  fd = creat (path02, mode);
    10651086  rtems_test_assert (fd >= 0);
     
    10931114  rtems_test_assert (status == 0);
    10941115
    1095   sprintf (path01, "%s/%s", dir02, name01);
     1116  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name01);
     1117  rtems_test_assert (rv < sizeof(path01));
    10961118  EXPECT_ERROR (EACCES, rename, path01, path02);
    10971119
     
    11121134  rtems_test_assert (status == 0);
    11131135
    1114   sprintf (path01, "%s/%s", dir01, name01);
     1136  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
     1137  rtems_test_assert (rv < sizeof(path01));
    11151138  EXPECT_EQUAL (0, unlink, path01);
    11161139  EXPECT_EQUAL (0, unlink, path02);
     
    11371160  int fd;
    11381161  int status;
     1162  int rv;
    11391163
    11401164  const char *name01 = "name01";
     
    11691193  rtems_test_assert (status == 0);
    11701194
    1171   sprintf (path01, "%s/%s", BASE_FOR_TEST, name02);
     1195  rv = snprintf (path01, sizeof(path01), "%s/%s", BASE_FOR_TEST, name02);
     1196  rtems_test_assert (rv < sizeof(path01));
    11721197  EXPECT_ERROR (EXDEV, rename, name01, path01);
    11731198
  • testsuites/fstests/support/fstest_support.h

    r6cd4a5c rf68401e  
    1010#define __FSTEST_SUPPORT_H
    1111
     12#include <rtems.h>
    1213
    1314#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.